Calling member function on a nullptr in C++

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 wit…


This content originally appeared on DEV Community and was authored by pikoTutorial

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;
}


This content originally appeared on DEV Community and was authored by pikoTutorial


Print Share Comment Cite Upload Translate Updates
APA

pikoTutorial | Sciencx (2025-04-29T08:17:00+00:00) Calling member function on a nullptr in C++. Retrieved from https://www.scien.cx/2025/04/29/calling-member-function-on-a-nullptr-in-c/

MLA
" » Calling member function on a nullptr in C++." pikoTutorial | Sciencx - Tuesday April 29, 2025, https://www.scien.cx/2025/04/29/calling-member-function-on-a-nullptr-in-c/
HARVARD
pikoTutorial | Sciencx Tuesday April 29, 2025 » Calling member function on a nullptr in C++., viewed ,<https://www.scien.cx/2025/04/29/calling-member-function-on-a-nullptr-in-c/>
VANCOUVER
pikoTutorial | Sciencx - » Calling member function on a nullptr in C++. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/04/29/calling-member-function-on-a-nullptr-in-c/
CHICAGO
" » Calling member function on a nullptr in C++." pikoTutorial | Sciencx - Accessed . https://www.scien.cx/2025/04/29/calling-member-function-on-a-nullptr-in-c/
IEEE
" » Calling member function on a nullptr in C++." pikoTutorial | Sciencx [Online]. Available: https://www.scien.cx/2025/04/29/calling-member-function-on-a-nullptr-in-c/. [Accessed: ]
rf:citation
» Calling member function on a nullptr in C++ | pikoTutorial | Sciencx | https://www.scien.cx/2025/04/29/calling-member-function-on-a-nullptr-in-c/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.