Skip to main content
GameDev.net gamedev.net
🔒 Locked

Header file question

Started by subnet_rx Dec 12, 2001 at 11:45 PM 2 replies 250+ views
Original Post
subnet_rx
subnet_rx
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
Oluseyi
Oluseyi
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!
Mark_C
Mark_C
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.