Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / December 2006

Tip: Looking for answers? Try searching our database.

Should my code implementation go in my .CPP or the .H header file?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bruce - 23 Dec 2006 05:12 GMT
I have seen sample code that is implemented in the .h header file ("java
style") and I have seen samples where the code was implemented in the
.CPP file.   Which is correct?  What is the best place to put my code
implementation in VC++ DotNet?

P.S.  The code is for a control where I am only going to distribute the
DotNet DLL.

Bruce
Bruno van Dooren [MVP VC++] - 23 Dec 2006 07:40 GMT
> I have seen sample code that is implemented in the .h header file ("java
> style") and I have seen samples where the code was implemented in the .CPP
[quoted text clipped - 3 lines]
> P.S.  The code is for a control where I am only going to distribute the
> DotNet DLL.

Whenever possible, your code implementation should be in the cpp file, and
the declaration in the h file.
exceptions:
- template classes should go into the h file completely because there is no
other option.
- IDE generated classes like Window Forms classes. These are implemented in
h files because the wizard does not understand the concept of difference
between declaration and implementation.

The reasons for the split is that a change in the h file causes a
recompilation in all the cpp files that include it. you want to prevent as
much as possible.
It is also the worldwide standard to program this way,
And finally, If you build libraries you have to have a separate header file
with the declarations anyway.

Signature

Kind regards,
   Bruno van Dooren
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"

Bruce - 23 Dec 2006 12:33 GMT
> The reasons for the split is that a change in the h file causes a
> recompilation in all the cpp files that include it. you want to prevent as
> much as possible.
> It is also the worldwide standard to program this way,
> And finally, If you build libraries you have to have a separate header file
> with the declarations anyway.

Thank you very much for the clarification.  I have been programming in
c++ for years but fairly new to DotNet.   I knew the reasons to use  CPP
files.  I just thought I had missed something new after seeing so many
DotNet samples in the header file.

Bruce

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.