Thread: problem of class definition and main function

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    50

    problem of class definition and main function

    Here, the class definition and the main function must be in the same file and the type of the main function must be void. It has 1 error & 1 warning:
    Code:
    #include <iostream>
    using namespace std;
    
    class X
    {
    
    }
    
    void main() //error: the class followed by void is illegal. 
    {
    }//warning: 'main' : function should return a value; 'void' return type assumed
    How to fix it? I really need your help.
    Last edited by Roy01; 11-19-2006 at 10:42 PM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    You need a semicolon after the closing brace in the class definition. Also, main() must return int to be standards-compliant.

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Well. It is int main(). Second when you are making a class you have to put a ';' at the end of the last '}' so it would be.
    Code:
    class X{
    };
    Woop?

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    50
    Thx!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  3. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  4. HELP!! Function Definition problem? Syntax Error I think..
    By felixgun in forum C++ Programming
    Replies: 12
    Last Post: 11-04-2006, 04:49 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM