Defining class methods

This is a discussion on Defining class methods within the C++ Programming forums, part of the General Programming Boards category; I know you are supposed to put the class declaration in a .h file and put the definition in a ...

  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,810
    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, 01:27 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

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