【发布时间】:2009-06-07 19:17:19
【问题描述】:
我在 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;
}
【问题讨论】:
标签: c++ visual-studio-2008 templates