Linking error when calling a function
When my code is calling a certain function, I'm getting an error:
H:\workspace\HW5\HW5\Manager.obj
Error 22 error LNK2019: unresolved external symbol "public: void __thiscall Shalishut::Task8_MoveVehicleFromBaseToBase(class Military *,char const *,char *,char *)" (?Task8_MoveVehicleFromBaseToBase@Shalishut@@QAEXPAVMilitary@@PBDPAD2@Z) referenced in function "public: void __thiscall Manager::TaskExecute(class Task *,class Military *,class Shalishut *,char * * const)" (?TaskExecute@Manager@@QAEXPAVTask@@PAVMilitary@@PAVShalishut@@QAPAD@Z) H:\workspace\HW5\HW5\Manager.objH:\workspace\HW5\HW5\Manager.obj
and:
error LNK1120: 1 unresolved externals H:\workspace\HW5\Debug\HW5.exe
开发者_如何转开发
When I'm not calling that function, everything is OK and the project builds.
Here is the code calling the function:
shalishut->Task8_MoveVehicleFromBaseToBase(military,licenseId,campNameA,campNameB);
and here is the function:
void Task8_MoveVehicleFromBaseToBase(Military* military,const char* licenseId,char* fromBase,char* toBase){
if (military->IsBaseExist(fromBase)){
if(military->FindBase(fromBase)->IsVehicleExist(licenseId)){
if (military->IsBaseExist(toBase)){
if(military->GetCountry()->IsRoadExist(military->FindBase(fromBase)->GetCityName(),military->FindBase(toBase)->GetCityName())){
military->FindBase(toBase)->AddVehicleToBase( military->FindBase(fromBase)->RemoveVehicleFromBase(licenseId) );
Time* time = Time::GetInstance();
long double distance = military->GetCountry()->GetRoadDistance(military->FindBase(fromBase)->GetCityName(),military->FindBase(toBase)->GetCityName());
Transport* transportToAdd = new Transport(time->GetTime(),(string)fromBase,(string)toBase,distance);
military->FindVehicle(licenseId)->AddTransport(transportToAdd);
}
}
}
}
}
I believe the function declaration needs to be:
void Shalishut::Task8_MoveVehicleFromBaseToBase(Military* military,const char* licenseId,char* fromBase,char* toBase) {
...
}
You didn't really provide us with header files so I'm assuming that function is a member of the shalishut class.
精彩评论