Skip to main content
gamedev.net
🔒 Locked

Problems breaking code into multiple files.

Started by Lord_Spatulator Jul 19, 2005 at 10:38 PM 0 replies 800+ views
Original Post
Lord_Spatulator
Lord_Spatulator
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.

Topic Locked

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

Sign in to reply to this topic.