Ok the point of this post is how I break my files up when i program. If anyone thinks there is a way to improve it or if someone wants to list how they do it.
So myself I break mine up like this:
main.cpp
functions.cpp
functions.h
classes.cpp
classes.h
Obviously the functions and classes are in more than one file. By using helper functions in one file and functions that player with how classes are being used in another etc.
One other question I have is - should I be using a main.h ?
No.
If the functions defined in main.cpp are only called by other functions in main.cpp, they don't need to be declared in a separate file. If they are called by functions in a different file, then they should be in functions.cpp, anyway
I went one step further once, because the project was pretty large, so I put every class in its own file, and also grouped the functions into different files, depending on the kind of operation they performed: some where file IO, others performed different kinds of IO, others just did some operation on data, others did text encoding conversion, and so on.
The result is a very fragmented, but also very organized, project directory. I will do it like this next time, too.
Ah alright but what if main was to have a couple of global variables for screen resolution etc? Would there be any point in making a header file for main then with those variables in it?
Only declare in a header things that will be needed in more than one file.
For example, your class declarations will be needed in classes.cpp and in anything that needs said classes.
If your globals are needed in functions, then they should be declared in a header:
1 2 3 4
//.cpp
int globalVar=0;
//.h
externint globalVar;
Note that it's also possible to not include the header and just declare the variable by hand in a .cpp that needs it (I've had to do this to avoid circular inclusions).