gpt4 book ai didi

C++ 主方法中的“ undefined reference ”

转载 作者:行者123 更新时间:2023-12-04 17:01:11 27 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





What is an undefined reference/unresolved external symbol error and how do I fix it?

(37 个回答)


去年关闭。




它看起来很基本,可能是由于初学者的错误,但我不明白为什么......
编译时,我从 int main() 收到如下错误:
“对'Hello::World::PaintService::PaintService() 的 undefined reference ”
油漆.cpp

using namespace Hello;
int main(int argc, char **argv) {
World::PaintService service;
service.start_painting(argc[1]);

}
PaintService 和 start_painting 定义如下:
油漆服务.h
namespace Hello {
namespace World {
class PaintService {
public:
PaintService();
void start_painting(...);
}; } }
油漆服务.cpp
namespace Hello { 
namespace World {
void start_painting(....) {
... //paint
}
} }
在调用 PaintService 服务后,在另一个类中调用类似 service.start_paint() 的 start 方法似乎很简单,但有些地方是错误的。我尝试了很多变体,但无法弄清楚:-/有人能指出我做错了什么吗?
谢谢!

最佳答案

要声明一个方法,您需要包含类的名称。

namespace Hello {
namespace World {

void PaintService::start_painting(....) { ... }
void PaintService::PaintService() { ... }

} // namespace World
} // namespace Hello
https://repl.it/repls/PunySaneSpools#main.cpp

关于C++ 主方法中的“ undefined reference ”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64346487/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com