#include <iostream>
using namespace std;
int main()
{
HelloWorld();
return 0;
}
void HelloWorld()
{
cout << "Hello, World" << endl;
}
I am getting the following compilation error with g++:
l1.cpp: In function 'int main()':
l1.cpp:5:15: error: 'HelloWorld' was not declared in this scope
You need to either declare or define the function before you can use it. Otherwise, it doesn’t know that
HelloWorld()exists as a function.Add this before your main function:
Alternatively, you can move the definition of
HelloWorld()before yourmain():