LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 945|回复: 2

关于linux下C++编程遇到的问题!

[复制链接]
发表于 2006-2-19 16:44:50 | 显示全部楼层 |阅读模式
关于linux下C++编程遇到的问题.为了解释的方便我描述如下:

定义一个名叫test.h的头文件。

class test
{
   public:
        test();
        ~test();
        void Setinf(int i,char c);
   private:
        int a;
        char ch;
};
定义实现的文件为test.cpp.

#include <iostream>
#include "test.h"

using namespace std;

test::test()
{
        cout<<"constructor is called!"<<endl;
}

test::~test()
{
        cout<<"destructor is called!"<<endl;
}

void test::Setinf(int i,char c)
{
        a=i;
        ch=c;
}

定义一个主函数main()所在的文件为pro.cpp.

#include <iostream>
#include "test.cpp"
//按照VC的话这里应该是inlclude"test.h",但是这样出错!包含test.cpp就没有问题,大虾解释一下!

using namespace std;

int main()
{
        test t;

        t.Setinf(5,'a');

        cout<<"hello "<<endl;
        return 0;
}
发表于 2006-2-19 18:21:49 | 显示全部楼层
猜你是这么编译的吧: g++ pro.cpp

应该如下编译: g++ test.cpp pro.cpp 就可以了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-19 18:40:17 | 显示全部楼层
“猜你是这么编译的吧: g++ pro.cpp”
强!正如你说的是那样编译的
谢谢斑竹!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表