Header file question

Started by
2 comments, last by subnet_rx 22 years, 4 months ago
I''m reading a book on C++ and I''m not quite getting something. You have the header file that prototypes your class. Then you have a .cpp that defines your functions. What do you include in your file that actually uses all of this? .h or .cpp? The book is making a header file, then a definition file that includes the header, then the actual problem-solving file that includes the definition .cpp file. But I see a lot of source files that include the .h. So where is the definition file? And if your file using the .h file IS the definition, why is the book using a seperate file for this? Can anyone make sense of my paragraph and then tell me what''s going on? subnet_rx
"There are two types of languages, those that everyone complains about, and those that no one uses."Standardized C++ LibrariesGamecron PC GamingA Christian Blog
Advertisement
You shouldn''t include .cpp files. You can, but strange things can happen. Under normal circumstances, you create your header and source (.cpp) files and include the header in other headers and/or source files that requires your class/function/variable definitions. The compiler handles all the code resolution and relocation.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
do you just put your definitions in the header?

subnet_rx
"There are two types of languages, those that everyone complains about, and those that no one uses."Standardized C++ LibrariesGamecron PC GamingA Christian Blog
I typed out a whom article on how linkers and compiler work but I decided that''d get confusing.

You put the class definitions in the header files. And you put it''s methods in its own CPP file.

You #include the .h file. The compiler and linker will handle the rest.

This topic is closed to new replies.

Advertisement