调用函数时出现链接错误
当我的代码调用某个函数时,出现错误:
H:\workspace\HW5\HW5\Manager.obj
错误 22 错误 LNK2019:无法解析的外部符号“public:void __thiscall Shalishut::Task8_MoveVehicleFromBaseToBase(类 军事 *,char const *,char *,char *)" (?Task8_MoveVehicleFromBaseToBase@Shalishut@@QAEXPAVMilitary@@PBDPAD2@Z) 在函数“public:void __thiscall Manager::TaskExecute(类任务*,类军事*,类 Shalishut *,char * * const)" (?TaskExecute@Manager@@QAEXPAVTask@@PAVMilitary@@PAVShalishut@@QAPAD@Z) H:\workspace\HW5\HW5\Manager.objH:\workspace\HW5\HW5\Manager.obj
和:
错误 LNK1120: 1 个无法解析的外部文件 H:\workspace\HW5\Debug\HW5.exe
当我不调用该函数时,一切正常并且项目构建。
这是调用该函数的代码:
shalishut->Task8_MoveVehicleFromBaseToBase(military,licenseId,campNameA,campNameB);
这是该函数:
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);
}
}
}
}
}
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);
}
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信函数声明需要是:
您并没有真正向我们提供头文件,因此我假设该函数是 shalishut 类的成员。
I believe the function declaration needs to be:
You didn't really provide us with header files so I'm assuming that function is a member of the shalishut class.