Advertisement Jump to content
Sign in to follow this  

Problems breaking code into multiple files.

This topic is 4929 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!