私が定義した別のクラスからクラス関数computeCivIndex()を呼び出そうとしましたが、LocationData :: computeCivIndex(string、int、int、float、float )と私のLocationData.cppに定義されていない関数computeCivIndex(文字列int、int、float、float) そして私はg ++ -Wall -W LocationData.h LocationData.cppを使いました。PointTwoD.h PointTwoD.cpp MissionPlan.cpp -o myProg .oをコンパイルする。2つのファイル間のリンクエラーC++
あなたが機能を実装していないためであるLocationData.h
static float computeCivIndex(string sunType_, int noOfEarthLikePlanets_, int noOfEarthLikeMoons_, float aveParticulateDensity_, float avePlasmaDensity_); /*calculate the possibility of life in the star system*/
};
LocationData.cpp
static float computeCivIndex(string sunType_, int noOfEarthLikePlanets_, int noOfEarthLikeMoons_, float aveParticulateDensity_, float avePlasmaDensity_)
{
int sunTypePercent = 0;
float civIndex;
// convert string suntype to suntype percent
if (sunType_ == "Type O")
{
sunTypePercent = 30;
}
if (sunType_ == "Type B")
{
sunTypePercent = 45;
}
if (sunType_ == "Type A")
{
sunTypePercent = 60;
}
if (sunType_ == "Type F")
{
sunTypePercent = 75;
}
if (sunType_ == "Type G")
{
sunTypePercent = 90;
}
if (sunType_ == "Type K")
{
sunTypePercent = 80;
}
if (sunType_ == "Type M")
{
sunTypePercent = 70;
}
//compute the CivIndex
civIndex = ((sunTypePercent/100) - (aveParticulateDensity_ + avePlasmaDensity_)/200) *
(noOfEarthLikePlanets_ + noOfEarthLikeMoons_);
return civIndex;
}
MissionPlan.cpp
float computeCivIndex[arraySize];
//compute civ index for all stored records
for (int i = 0; i < (entryNo+1); i++)
{
string suntype = locData[i].getSunType();
int earthlikeplanets = locData[i].getNoOfEarthLikePlanets();
int earthlikemoons = locData[i].getNoOfEarthLikeMoons();
float partdensity = locData[i].getAveParticulateDensity();
float plasdensity = locData[i].getAvePlasmaDensity();
locData[i].computeCivIndex(suntype,earthlikeplanets, earthlikemoons , partdensity, plasdensity);
point2d[i].setCivIndex(computeCivIndex[i]);
}
cout << "Computation Completed! (" << entryNo <<" records were updated)" << endl;
このメソッドは静的なので、オブジェクトで呼び出すことはできません。 –