Click to See Complete Forum and Search --> : Splitting up code?


HKothari
January 27th, 2008, 09:48 AM
I was wondering, is it possible to split up your code into seperate files, like cpp files, that contained the functions? If so, would you have to "include" them or would they just be linked in?

laserlight
January 27th, 2008, 09:50 AM
Yes. Typically, you would place class definitions and function prototypes into headers, then implement the classes and functions in source files. You would include the relevant headers in the respective source files.

HKothari
January 27th, 2008, 10:14 AM
ok, alright, thanks.

TheCPUWizard
January 27th, 2008, 10:56 AM
To take LaserLight's statements a bit further.

Typically there is one header (.h/.hpp) and one implementation (.cpp) per class.

However for large classes it is also possible to divide the functions among multiple .cpp files so they are easier to track (or for other reasons like some of the functions being created by a code generator.

It is generally a bad idea (and difficult) to split a header into multiple files, although it is physically possible via includes in the middle of the class definition. :sick: