#include <iostream>
using namespace std;
int main()
{
HelloWorld();
return 0;
}
void HelloWorld()
{
cout << "Hello, World" << endl;
}
我收到以下 g++ 编译错误:
l1.cpp: In function 'int main()':
l1.cpp:5:15: error: 'HelloWorld' was not declared in this scope
原文由 MatthewSot 发布,翻译遵循 CC BY-SA 4.0 许可协议
您需要先声明或定义该函数,然后才能使用它。否则,它不知道
HelloWorld()
作为函数存在。在你的主要功能之前添加这个:
或者,您可以将 --- 的定义移到 ---
main()
HelloWorld()
之前: