我有 3 个类 LocationData、PointTwoD 和 MissionPlan。类 MissionPlan 是我的驱动程序类,它将运行我的所有程序。在我的 LocationData 中,有一个静态方法接收来自用户的 5 个输入,它将计算为浮点数并返回值。如前所述,MissionPlan 是我的驱动程序类,所有输入都将链接到我的 MissionPLan 类中,我尝试在 MissionPlan 中调用静态方法来计算值 LocationData::computeCivIndex(s,i,j,k, l); 但它返回给我一个很长的错误。
/tmp/ccK8Rwha.o: 在函数MissionPlan::MissionPlan()':
test.cpp:(.text+0x9f1): undefined reference to
LocationData::computeCivIndex(std::basic_string, std::allocator >, int, int, float, float)' /tmp/ccK8Rwha.o: 在函数‘MissionPlan::MissionPlan() ':
test.cpp:(.text+0xfb7): undefined reference to `LocationData::computeCivIndex(std::basic_string, std::allocator >, int, int, float, float)' collect2: ld 返回 1 个退出状态
class LocationData
{
private:
//codes for initilization
public:
LocationData();
LocationData(string,int,int,float,float);
//getter and setter methods..
static float computeCivIndex(string,int,int,float,float);
};
class MissionPlan
{
public:
MissionPlan();
};
static float computeCivIndex(string sunType, int noOfEarthLikePlanets,int noOfEarthLikemoons, float aveParticulateDensity, float avePlasmaDensity)
{
LocationData data; //not sure if i need this
//methods to caculate...
float ci = 0.0;
return ci;
}
MissionPlan::MissionPlan()
{
int choice; // to capture what user inputs into menu
int count=0;
//codes to get user inputs
cin>>choice;
for(;;)
{
if(choice == 1)
{
int i,j,x,y;
float k,l;
string s;
//codes to get user inputs
LocationData::computeCivIndex(s,i,j,k,l); //the part where error occurs
count++;
}
else if(choice == 2)
{
cout<<"Computation completed!"<<endl;
break;
}
else if(choice==3);
else if(choice==4);
else
cout<<"Please enter number 1 to 4 only!"<<endl;
}//end of do loop
}//end of MissionPlan()
int main()
{
MissionPlan plan;
MissionPlan();
return 0;
}