No "void main(int argc, char *argv[])" for Visual Studio C++ 6.0?

This is a discussion on No "void main(int argc, char *argv[])" for Visual Studio C++ 6.0? within the C++ Programming forums, part of the General Programming Boards category; Hi. I am making a simple console program that takes in command line arguement using Visual Studio C++ 6.0. In ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    7

    Question No "void main(int argc, char *argv[])" for Visual Studio C++ 6.0?

    Hi.

    I am making a simple console program that takes in command line arguement using Visual Studio C++ 6.0.

    In Turbo C++ 3.0, I can use "void main(int argc, char *argv[])" to takes in arguement, however when I do this in Visual Studio, it gives me an error:
    : error C2731: 'main' : function cannot be overloaded
    : see declaration of 'main'

    May I know how I can do the "void main(int argc, char *argv[])" for Visual Studio C++?

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    lol lol rflmao lol.............lol!!!!!!........wooo!

    don't use void main....ever........

    try:
    int main(char **argv, int argc)
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    oh yea...you're gonna get some static for void main.....by just about everyone
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,810
    Lets see what the C++ standard has to say
    3.6.1 Main function
    1 A program shall contain a global function called main, which is the designated start of the program. It is
    implementationdefined
    whether a program in a freestanding environment is required to define a main
    function. [Note: in a freestanding environment, startup
    and termination is implementationdefined;
    startup
    contains the execution of constructors for objects of namespace scope with static storage duration; termination
    contains the execution of destructors for objects with static storage duration. ]
    2 An implementation shall not predefine the main function. This function shall not be overloaded. It shall
    have a return type of type int
    , but otherwise its type is implementationdefined.
    All implementations
    shall allow both of the following definitions of main:
    int main() { /* ... */ }
    and
    int main(int argc, char* argv[]) { /* ... */ }
    Woop?

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Don't forget to return something from main now that you're using int main. Returning 0 is the generally accepted sign of success, and returning 1 is a generic error. You can however, return whatever code you want, as the whole idea is to allow the OS to confirm proper execution of your program.

    edit: Though from the looks of those errors, ad knowing what VS is like, main may already be defined somewhere. Look around in other files VS created for you when you started this project if using "int main" doesn't fix the problem.
    Last edited by sean; 12-25-2004 at 07:34 AM.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >: error C2731: 'main' : function cannot be overloaded
    >: see declaration of 'main'
    Are you prototyping main improperly? Aside from returning void that is. People coming from very old style C will run into this error when they try to use a K&R style function declaration with an ISO style function definition. Because C++ never had K&R style functions, the second is parsed as an overload.
    Code:
    int main();
    
    int main(int argc, char *argv[])
    {
      //...
    }
    Post your code. I gave my crystal ball away.
    My best code is written with the delete key.

  7. #7
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by sean_mackrory
    Don't forget to return something from main now that you're using int main. Returning 0 is the generally accepted sign of success, and returning 1 is a generic error. You can however, return whatever code you want, as the whole idea is to allow the OS to confirm proper execution of your program.
    you don't necessarily need to return anything from main, but I think this is a very good point...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Yes you do. Don't you pay attention to your compiler's warnings? Main always returns something. Therefore, just like with any other function that has a return value, all paths of exeuction must end in something being returned. Otherwise your compiler, and all the people on the C board who actually know what they're talking about, will complain at you.

    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Pssst quzah this is c++. You don't have to put return 0; in main. Its implicit.
    Quote Originally Posted by Section 3.6.1.5
    [...]If control reaches the end of main without encountering a return statement, the effect is that of executing
    return 0;

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well if you're going to be that way about it. :P

    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Give him a break. He's engaged. And she knows how to use Linux. Would your mind be on C++ right now?

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Would your mind be on C++ right now?
    Um...yes.
    My best code is written with the delete key.

  13. #13
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    The exception that proves the rule...

  14. #14
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,742
    > You don't have to put return 0; in main. Its implicit.
    But only if your C++ compiler is up to the new standard.
    Crusty old C++ compilers like those used by the OP may not have an implicit return 0;

  15. #15
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Well I am assuming that the OP is using VS 6 since thats in the title

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 09:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 09:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21