I'm using Borland v.4.52. How do you make, include and use your own header files?
Printable View
I'm using Borland v.4.52. How do you make, include and use your own header files?
Well, here is an example of a basic header file.
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 lineCode:// Example.h
#ifndef _EXAMPLE_H_ // says, if it isn't defined, define
#define _EXAMPLE_H_
class cExample {
private:
int m_x;
int m_y;
public:
inline int GetX( void ) { return ( m_x ); }
inline int GetY( void ) { return ( m_y ); }
};
#endif /* _EXAMPLE_H_ */
#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.
This would declare an instance of the class and you could access the public members as you normally would. Hopefully this helps you some.Code:int main( void )
{
cExample cEx;
return ( 0 );
}