473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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


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
Dec 23 '06 #1
2 1314
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.
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.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Dec 23 '06 #2
Bruno van Dooren [MVP VC++] wrote:
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
Dec 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
10
by: da Vinci | last post by:
Hello. First off, I am not sure of the exact jargon used, so I will ask a question regarding it. Then on to my other question. When you use things like cout and cin from the iostream header...
38
by: venkatesh | last post by:
int *p=20; printf("%d",*p); printf("%d",p); the above code prints the output as somegarbage value //for *p(may be address 20 //for p why can you explain
175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
15
by: TT (Tom Tempelaere) | last post by:
Hey everyone, I noticed that unlike C#, managed C++ still uses headers and implementation files. My question is, is there any consensus of where to put the implementation of the managed class? ...
4
by: Shil | last post by:
Hi, In VC++.Net 2005 visual studio, if I create a new winform drag and drop a button, then double click it to write click event code, then it auto generates the template code for the event in...
6
by: Abubakar | last post by:
Hi, I'm working on a project in unmanaged c++. I was writing all (most of) my code in header files, that is, no seperation of code in header and cpp files, as usually is done in c++. I feel pretty...
11
by: Eigenvector | last post by:
I apologize if this is a trivial question, but it's always made me wonder when I have to compile my code. There are some #includes that you don't really need to reference in your library and...
4
by: Steven T. Hatton | last post by:
<quote url="http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=53&rl=1"> exported Templates Last updated Sep 6, 2006. exported Templates The separate compilation model enables...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.