Header Files

This is a discussion on Header Files within the C++ Programming forums, part of the General Programming Boards category; I'm using Borland v.4.52. How do you make, include and use your own header files?...

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Montreal, Quebec

    Question Header Files

    I'm using Borland v.4.52. How do you make, include and use your own header files?

  2. #2
    Registered User
    Join Date
    Apr 2002
    Well, here is an example of a basic header file.

    // Example.h
    #ifndef  _EXAMPLE_H_ // says, if it isn't defined, define
    #define _EXAMPLE_H_
    class cExample {
         int m_x;
         int m_y;
         inline int GetX( void ) { return ( m_x ); }
         inline int GetY( void ) { return ( m_y ); }
    #endif /* _EXAMPLE_H_ */
    This might seem a little confusing at first but basically this is just a simple class that your main.cpp file can use. Make sure you add the line

    #include "Example.h"

    to your main.cpp in the beginning. Using quotes as opposed to the brackets you are accustomed to means that it is a header file you defined and is located in the directory your source code is located in. Now if I wanted to declare an instance of this class in my main.cpp you would write it like this.

    int main( void )
         cExample cEx;
         return ( 0 );
    This would declare an instance of the class and you could access the public members as you normally would. Hopefully this helps you some.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 04:25 PM
  2. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 12:21 PM
  3. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 07:12 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM

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