DEV Community

Cover image for Calling member function on a nullptr in C++
pikoTutorial
pikoTutorial

Posted on • Originally published at pikotutorial.com

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’
Enter fullscreen mode Exit fullscreen mode

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;
}
Enter fullscreen mode Exit fullscreen mode

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;
}
Enter fullscreen mode Exit fullscreen mode

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

ACI image

ACI.dev: Fully Open-source AI Agent Tool-Use Infra (Composio Alternative)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Check out our GitHub!

Join the Runner H "AI Agent Prompting" Challenge: $10,000 in Prizes for 20 Winners!

Runner H is the AI agent you can delegate all your boring and repetitive tasks to - an autonomous agent that can use any tools you give it and complete full tasks from a single prompt.

Check out the challenge

DEV is bringing live events to the community. Dismiss if you're not interested. ❤️