在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