|
test.h:
#include<string>
#include<vector>
class Tel
{
public:
string getName(void);
string getNum(void);
void setName(string);
void setNum(string);
private:
string name;
string num;
};
void insert();
void show();
test.cpp: 这是个实现文件
#include<vector>
#include<string>
#include"test.h"
string Tel::getName()
{
return name;
}
string Tel::getNum()
{
return num;
}
void Tel::setName(string n)
{
name = n;
}
void Tel::setNum(string n)
{
num = n;
}
为什么我编译test.cpp始终通不过呢?
报错误如下:
root@/mydoc/c++>g++ test.cpp
In file included from test.cpp:3:
test.h:7: error: syntax error before `)' token
test.h:8: error: syntax error before `)' token
test.h:9: error: `string' was not declared in this scope
test.h:9: error: invalid data member initialization
test.h:9: error: (use `=' to initialize static data members)
test.h:9: error: variable or field `setName' declared void
test.h:10: error: `string' was not declared in this scope
test.h:10: error: invalid data member initialization
test.h:10: error: variable or field `setNum' declared void
test.h:12: error: 'string' is used as a type, but is not defined as a type.
test.h:13: error: 'string' is used as a type, but is not defined as a type.
test.cpp:4: error: syntax error before `::' token
请指点,顺便问下,假如我的 主文件为main.cpp,里面只需要引用test.h就能用实现文件里实现的功能了吧 |
|