|
-
Dec 15th, 2003, 11:14 AM
#1
Thread Starter
Member
when to use .cpp and .h files?
Ok i am currently on mission to improve my coding practice. having learned from books i have never really learned when to use a .cpp file.
I know that there are differences but never to sure exactly what they are so i normally take the easy way out and use header (.h) files.
What is wrong with me using one .cpp file and all the rest as .h files?
is there anything wrong with that?
Thanks to anyone who can clear this up for me
-
Dec 15th, 2003, 11:33 AM
#2
I use a .hh for my implimentations instead of .cc/.hh style. I just put the entire declaration within the header.
And then the program goes in the cc.
I think it's just mainly style, I don't think it really matters much but it might with certain companies.
btw, I use .cc instead of .cpp and .hh instead of .hpp (if you're going to have a file naming scheme, use .cc/.hh or .cpp/.hpp. I know alot of people who use .c/.h for C code where .cc/.hh and .cpp/.hpp is for C++ code so using a .cpp/.h might confuse someone else using your code)
-
Dec 15th, 2003, 11:43 AM
#3
Header files (.h, .hh, .hpp, .hxx, whatever) are never compiled directly, only included. Every module file (.c, .cpp) results in one object file, headers don't. The main issue is recompilation time, really. If you change your code, you only need to recompile those parts directly affected by that change. If your app is only one module (one .cpp file), you need to recompile everything, and C++ is very slow to compile.
It can really mean the difference between seconds and hours for large projects.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|