main in a class?

This is a discussion on main in a class? within the C++ Programming forums, part of the General Programming Boards category; Ok, my past C++ experience has all been in the Windows environment using MFC so I've never really worried about ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    22

    main in a class?

    Ok, my past C++ experience has all been in the Windows environment using MFC so I've never really worried about a main(...) function as the App Wizard took care of all that for me.
    When writing a console app with a main(...) function, is it ever reasonable to put main(...) in a class as a member function or should it always be kind of hanging out there as a global so to speak? If it can be put in a class, how does the OS know where the entry-point for the exe is?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I don't think you can put main() in a class (except in Java).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    Just leave it global and have it call the class member function you want to run.

  4. #4
    Registered User
    Join Date
    May 2005
    Posts
    22
    That's kind of what I figured I'd end up doing. Now for a twist on the question though, how do I model this type of program (for instance in Rational Rose)? The classes are easy, but how do you model the "global" stuff? This is probably the wrong forum to ask this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inherite nonvirtual class functionality
    By DrSnuggles in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2009, 01:52 PM
  2. Replies: 3
    Last Post: 10-31-2005, 11:05 AM
  3. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM

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