Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Header Files

Status
Not open for further replies.

pwel

Programmer
Aug 18, 1999
79
GB
Could anyone advise me on the correct way to split up my code into seperate files. i.e.<br>
Do i put my classes and thier functions together in a .h file, or, do the classes go into a .h file and thier functions into a seperate .cpp file?<br>
<br>
I have successfully put my function declarations and #includes into a .h file which i include in my main .cpp file, the problem lies with classes and thier functions.<br>
<br>
Any help would be much appreciated.<br>
<br>
Paul Welding.
 
I would say that this is a matter of personal preference. <br>
My personal preference is to put the class definitions in the .h and the implementations into .cpp, but often if a member function is only one line (say an access function) I will go ahead and put the implementation right into the header file. <br>
<br>
For example, my .h may look like this<br>
<br>
class widget<br>
{<br>
protected:<br>
int foo;<br>
long bar;<br>
public:<br>
widget(int, long);<br>
~widget();<br>
int GetFoo() {return foo;}<br>
long GetFooBar();<br>
}<br>
<br>
But since the member function GetFooBar() along with the constructor and destructor involve more detailed processing, I would put their implementations in the .cpp.<br>
<br>
Also, it used to be harder to debug actual code that was included in a header file since older debugger versions (MS VC++ 1.5 for example) wouldn't step into .h files, but that all works fine nowdays.<br>
<br>
Good Luck!<br>
<p>Pat Gleason<br><a href=mailto:gleason@megsinet.net>gleason@megsinet.net</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top