Welcome to the next pikoTutorial!
The error we’re handling today is a C++ compilation error:
‘::main’ must return ‘int’
What does it mean?
The requirement for main
to return an integer stems from convention and standardization within the programming languages. In C and C++, the main
function is typically defined with a return type of int
. This return type allows the program to communicate its exit status back to the operating system or the environment where it was executed.
The integer returned by main
conventionally signifies the status of the program execution to the operating system. A return value of 0
typically indicates successful execution, while any non-zero value indicates an error or an abnormal termination. This simple mechanism allows scripts and other programs calling your program to determine if it completed successfully or encountered an issue.
How to fix it?
If you see this error, you most likely have the main
function declared to return a type other than int
, for example:
float main()
{
return 3.14;
}
Returning float
or any type other than int
is unfortunately not allowed in C++, so the only thing to do is to make the main
function return an integer:
int main()
{
return 0;
}