Thread: Making .h files

  1. #1
    Registered User Diamonds's Avatar
    Join Date
    Oct 2002
    Posts
    68

    Unhappy Making .h files

    I feel really bad for asking this, but I've completely forgotten how to make .h files.

    Suppose i had this class. How would I seperate it into .h and .cpp files:
    Code:
    class P {
    public:
          P();
          ~P();
    void      setI(int num);
    void printP();
    private:
          int i;
    };
    
    P::P() {}
    
    P::~P() {}
    
    void P::setI(int num) {
          i = num;
    }
    
    void P::printP() {
           cout<<i<<endl;
    }

  2. #2
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    I *.h

    Code:
    class P {
    public:
          P();
          ~P();
    void      setI(int num);
    void printP();
    private:
          int i;
    };
    and in *.cpp
    Code:
    P::P() {}
    
    P::~P() {}
    
    void P::setI(int num) {
          i = num;
    }
    
    void P::PrintP() {
           cout<<i<<endl;
    }

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    93

    dont forget

    yep he's right.. don't forget that at the top of the

    Boobies.cpp file to #include "Boobies.h"
    and in the header file it would be wise to write

    Code:
    #ifndef Boobies_h
    #define Boobies_h
    at the top and
    Code:
    #endif
    at the bottom...

  4. #4
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    UHH!! AHUUHH!!

    He said: #include "Boobies.h"

    HUUUHUU!! AHUUA!! AHA!

    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Get .cpp and .h files to communicate...
    By yaya in forum C++ Programming
    Replies: 6
    Last Post: 11-25-2008, 12:45 AM
  2. Header files in .h
    By swgh in forum C++ Programming
    Replies: 5
    Last Post: 05-29-2008, 08:58 AM
  3. Making a folder and moving files into it?
    By HLA91 in forum C Programming
    Replies: 1
    Last Post: 01-27-2008, 12:38 PM
  4. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  5. .cpp and .h files - organization
    By ChadJohnson in forum C++ Programming
    Replies: 4
    Last Post: 01-12-2006, 11:40 PM