问题与类和类型
问题描述:
我有我想要的类型问题与类和类型
class ship{
public:
vector <int> xp;
vector <int> yp;
vector <bool> pos;
shipType vessel;
bool active;
ship(){}
void randommethods(){
blah;
}
};
我想在舰队类包括船型的阵列中使用的一类。
class fleet{
public:
ship boat[7];
boat(){}
};
我已经在船队的源文件中包含了ship.h的头文件,但它不能识别ship作为类型。
fleet.cpp:12: error: ISO C++ forbids declaration of ‘boat’ with no type
fleet.cpp:13: error: declaration of ‘int fleet::boat()’
fleet.cpp:11: error: conflicts with previous declaration ‘ship fleet::boat [7]’
我可以使用类似的声明来处理ship类型的变量和ship.cpp中的所有成员方法。如果我做错了任何帮助,将不胜感激。
答
在您的船队级代码中,您声明了名为boat的array of ship
(商船[7])和名为boat的船舶AND function member returning int
(boat(){})。您尝试在一个名称空间中声明两个具有相同名称的不同实体,这是错误的。编译器试图告诉你的东西。
我想你想赖特舰队类水木清华这样的默认构造函数:
class fleet{
public:
ship boat[7];
fleet(){} //fleet, not boat
};
谢谢,我不能相信我没有看到这一点。它让我在最后45分钟内挂断电话。 – vcelloho 2011-04-23 06:08:01
然后你可以接受答案)) – beduin 2011-04-23 06:10:19