任何一个知道如何解决这个错误?我不太确定它出错的地方。错误C++不能调用没有对象的成员函数
MissionPlan.cpp: In function ‘int computeCivIndex(PointTwoD*, int)’:
MissionPlan.cpp:132: error: cannot call member function ‘float LocationData::computeCivIndex(std::string, int, int, float, float)’ without object
的源代码:
int computeCivIndex(PointTwoD list[], int entry)
{
int record = 0;
for (int z = 0; z < entry; z ++)
{
LocationData d=list[z].getLocationData();
float civIndex = LocationData::computeCivIndex(d.getSunType(), d.getNoOfEarthLikePlanets(), d.getNoOfEarthLikeMoons(), d.getAveParticulateDensity(), d.getAvePlasmaDensity());
if(civIndex != list[z].getCivIndex())
{
record++;
}
list[z].setCivIndex(civIndex);
}
return record;
}
使'LocationData :: computeCivIndex'静态(如果可以的话),或者如果它不能通过对象调用它。 – StoryTeller
使你的mehtod静态 – MRB
如错误所述,你需要一个对象实例。你的意图是什么?你打算做什么? –