.hpp and .cpp

Aug 20, 2015 at 7:55pm
I'm not completely sure but I think .hpp is where we use declare the the class and his member function and datas and in .cpp is where we define thoses member functions...my question is the nextif I declare a .cpp as .hpp something will happen??, could It work in the same way??

Aug 20, 2015 at 8:03pm
Try to be more clear on what your issue or concern is.
Aug 20, 2015 at 8:06pm
If I had any program where I fiend some .cpps and some .hpps what would happen if I changed all .cpps to .hpp less the main.cpp( It would keep that one with his original extension...??
Aug 20, 2015 at 8:06pm
just I want to know if the behaviour would change...
Aug 20, 2015 at 8:10pm
If you change a .cpp file to .hpp, the file would not be compiled.
IDEs only compile .cpp files.


Aug 20, 2015 at 8:15pm
ok, but in fact it's not important what each file contains......as long as the main declares at the begining each .hpp it will work, wont it??.or the main delcare a few .hpp and those one declared in the main declare the rest that complete the whole program. I hope It's understandable...



Aug 20, 2015 at 8:16pm
IDEs only compile .cpp files.
It would compile anything if you would be persistent enough.

Header files (those with extension .hpp) are not compiled. At all. All what they are good for is to copy-passte into actual implementation files. #include is a glorified copy-paste. THere is nothing magic in it. YOu can include anything: .hpp, .cpp, .txt, .exe... And its content would just be pasted inside your file which does inclusion.
Last edited on Aug 20, 2015 at 8:19pm
Aug 20, 2015 at 8:21pm
I think I do...:), what I mean is, all the .cpp dont have to be declare in the main, if It's the just single one .cpp that I have...while the rest of the .hpp all declare in the ones are already declared in the main( always declaring in each .hpp what is nedded)
Aug 20, 2015 at 8:25pm
ok, clear...but then why is the reason we usually declare member functions in.hpp and define them in .cpp, It's just a convention, isnt it?
Aug 20, 2015 at 8:30pm
You're going down the wrong path. You don't want to do things that way.

.hpp and .cpp files have distinct purposes. .hpp files contain declarations, while .cpp files contain implementation of what is declared in the .hpp file. You don't want to put implementations in a .hpp file. Doing so can cause problems including multiply defined symbols or functions.
Aug 20, 2015 at 8:33pm
ok, thank you both, I have got it clearly...
Topic archived. No new replies allowed.