在Visual Studio 2008中出现以下错误:错误C2248:'Town :: Town':无法访问类'Town'中声明的私有成员。它看起来像构造函数无法访问它自己的类的成员。任何想法发生了什么? 下面的代码:构造函数不能访问自己类的私有成员
我有这样的:
template<class T> class Tree{...}
这个类:
class Town{
Town(int number):number(number){};
...
private:
int number;
};
这也是使用的这个类:
class Country{
public:
StatusType AddTown(Shore side, int location, int maxNeighborhoods);
private:
Tree<Town> towns[2];
...
}
而这里的AddTown功能:
StatusType Country::AddTown(Shore side, int location, int maxNeighborhoods){
if (maxNeighborhoods<0 || location<0){
return INVALID_INPUT;
}
Town* dummy= new Town(location);//Here be error C2248
if (towns[side].find(*dummy)!=NULL){
delete dummy;
return FAILURE;
}
SouthBorder* dummyBorder;
(side==NORTH)?dummyBorder=new SouthBorder(location,0):dummyBorder=new SouthBorder(0,location);
if (southBorders.find(*dummyBorder)!=NULL){
delete dummyBorder;
return FAILURE;
}
towns[side].add(*dummy);
delete dummyBorder;
return SUCCESS;
}
谢谢。这是一个愚蠢的错误...... – 2009-06-07 19:25:02