Functions not working

I have a rather big project that I’m working on, terrain engine… if you wanna know more about it check it out at but that’s not the point. The thing is I have like 10 cpp files and there is a main one with all the opengl drawing functions and what not. So, I have classes for all of them, like a menu class, a build class, a player class. If I call the class from the main file, like if i call a function from that main file it works fine. But, if I call a function from one of the other files it won’t run the function if it’s not in the same class. I have no idea what the problem is. If I call the function from within a certain class to another class in the main file it works fine too, so that means it’s just a file problem, nothing about the classes. If anyone knows what the problem may be I would appreciate it greatly, thanks.

I don’t know if this is the best solution, but I got it to work. First, create a header file for your main cpp file. Include all of your functions in the cpp file in the header. Now you just #include<header.h> in your other cpp files that you want to call functions from the main program. Then it should recognize the functions. I hope this helps.

Well, i have separate headers for each of the different cpp files, so putting them all in one header wouldn’t be ideal unless I want a whole lot of code in one file, which I don’t find to be very easy to move around in. Ummm, it’s not like I get any errors or anything, I mean it runs and everything, just whenever I call the function… such as pPlayer.Move(x,y) or what not, it won’t work unless I’m calling it in the main file. I think it may have to do with the fact that I declared the class for the first time in there, like that is where I have all the… Player pPlayer; type things, I forget what they’re called. Anyway, anyone got any other ideas?

What littledevore was suggesting is that for all the functions in your main file, put the prototypes of those functions in a separate header. Then in the .cpp files for any of the classes that need to use those functions, you #include that header.

If you have a class that needs access to another class, you also have to #include the header to that other class.

If you had a better understanding of C++, you would see why this has to be. Each .cpp file is compiled separately, from top to bottom. Before a function can be used it has to be defined or declared in the scope of that file, either directly or in an included file. It’s only after all the .cpp files are compiled that they are linked together into a single binary.