dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: How to solve error C2731: 'main': function cannot be overloaded

  1. #1
    Join Date
    Jul 2018
    Posts
    4

    How to solve error C2731: 'main': function cannot be overloaded

    Why does the following code cause this error?

    Code:
    //
    int main(int argc, char *argv[])
    {
        float current_temp;
        int i = 0;
        int j;
        uchar val;
        int NumDevices = 0;
        int portnum = 0;
        uchar sernum[8];
        char msg[128];
        int msglen = 127;
        int status = 0;
        int result;
    
        if (argc <= 1)
        {
            //etc.
            //etc.
    
            sprintf_s(msg, msglen, "Exiting with status %d", status);
            LOGMSG(INFO, msg);
            return status;
        }
    Thanks - Rowan
    Last edited by 2kaud; June 18th, 2019 at 03:51 AM. Reason: Added code tags

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,406

    Re: How to solve error C2731: 'main': function cannot be overloaded

    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,728

    Re: How to solve error C2731: 'main': function cannot be overloaded

    I guess that somewhere in your code you have another function called main with a different set of arguments. You can only have one non-member function called main in your program.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.1.6)

  4. #4
    Join Date
    Jul 2018
    Posts
    4

    Re: How to solve error C2731: 'main': function cannot be overloaded

    Quote Originally Posted by 2kaud View Post
    I guess that somewhere in your code you have another function called main with a different set of arguments. You can only have one non-member function called main in your program.
    You were right. There was a "hello world" version of main elsewhere in my code. It must have been in the sample file that I based it on. Now fixed - thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)