Sign in to follow this  
Lord_Spatulator

Problems breaking code into multiple files.

Recommended Posts

Hey guys, im having some trouble breaking up my code, I'd like to put all of my global variable initializations into a file other than main.cpp, and I'd also like to put my funtion declerations into another file also. but if I try either, I get errors about multiple instance problems and stuff... I'm programming in C++, and using bloodshed Dev-Cpp. And I did try hitting the Rebuild All button instead of just the recompile one, that didn't fix the problem. What I've got at the moment is line 1: #include "header.cpp" and in my header.cpp file, I've got all of my #includes (stdio, SDL, math.h, vector, etc) followed by
template <class T>
inline std::string toString(T data){
	std::ostringstream s;
	s << data;
	return s.str();
}
which i use to convert integers into strings, and found that this is th eonly place I can put that code without errors. followed by #include "globals.cpp" which is where I would like to create all of my global variables, but at the moment I've only got global constant variables in there, if I try putting the global variables in there as well I get errors. Back in includes.cpp I'd like to add #include fndecs.cpp or something similar to include all of the function declerations, but i get similar errors if I have those outside the main.cpp also. I've never done a program with code in multiple files before either, next ill be trying to get my classes into their own files, and then group all of the SDL fns into a file, and so on, untill I no longer have a 1200 line main.cpp. Any help could be appreciated. Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this