调用函数时出现链接错误

发布于 2024-09-24 16:12:14 字数 1783 浏览 2 评论 0原文

当我的代码调用某个函数时,出现错误:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福丶如此 2024-10-01 16:12:14

我相信函数声明需要是:

void Shalishut::Task8_MoveVehicleFromBaseToBase(Military* military,const char* licenseId,char* fromBase,char* toBase) {
...
}

您并没有真正向我们提供头文件,因此我假设该函数是 shalishut 类的成员。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文