Thread: Defining class methods

  1. #1
    ---
    Join Date
    May 2004
    Posts
    1,379

    Defining class methods

    I know you are supposed to put the class declaration in a .h file and put the definition in a .cpp file but is it wrong to define small class methods in the .h file with the declaration? MS VC++ Toolkit 2003 doesn't seem to mind but should I avoid doing it?

    When I say small I mean something like this:

    Code:
    class whatever{
      int x;
    
      public:
        int get_x(){
          return x;
        }
    };

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    There is nothing wrong with doing that I believe. It is more a stylistic issue than a correctness issue. Because if you are defining inline functions and such you can only define them in the header.
    Woop?

  3. #3
    ---
    Join Date
    May 2004
    Posts
    1,379
    ok thx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. class methods to cout stream
    By shintaro in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2008, 07:27 PM
  2. Replies: 8
    Last Post: 10-02-2005, 12:27 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM