I'm sorry if this question has been asked before or if i am asking it in the wrong place.
I'm trying to figure out how to recognize a call to a .cpp file from inside another one. I understand a fair amount about C++ but I've never encountered a situation complicated enough to warrant a program split into more than a single file.
If anyone can explain this to me or point me in the right direction to learn what i need to know i would greatly appreciate it.
When you compile a cpp file, you get out a binary object file. One per cpp file.
If your cpp file uses a function that is defined in some other cpp file, that's fine. All that is needed is that the compiler has been told what the correct input and output to that function is, and it will essentially leave an indicator that at this point, the flow of programme execution goes off into this other function, and the linker will fill in the gaps when it finds that other function. Usually, the compiler knows the correct inputs and outputs because you have included the right header file, or you have forward-declared the function.
When you link those object files together to make your executable program, the linker goes looking for each function that is called; so long as it can find it in some object file, all is good. If it cannot, you get the well known "undefined reference" error.
So, to use more than one cpp file, simply write each cpp file, compile each one into object files, and then link them all. The linker will find the main function and start there, looking for each function called in turn, and looking for each function they call, and so on.
If you're using an IDE of some kind, it probably handles this for you and all you need to do is add each new cpp file to the "project" or whatever it uses to indicate all the cpp files are to be compiled and linked together.
Thank you for your insight. Unfortunately i must not have been as clear as i should have. I'm actually working with existing source. A friend and i are working on a source port of an old game. There are two open source, source ports that we are using as a base for our project. One of which has reliable net code (online support) but the gameplay mechanics have been tampered with from the original version of the game. The second source port maintained the original gameplay mechanics but the net code was horrendous. Essentially we are trying to Frankenstein the two together to make a source port that preserves the original gameplay and has an online multiplayer that doesn't lag like a beast.
If i understand this properly your saying that i have to essentially read through the entire source and determine which functions are called across files?
I'm trying to figure out how to recognize a call to a .cpp file from inside another one. I understand a fair amount about C++ but I've never encountered a situation complicated enough to warrant a program split into more than a single file.
Surely you do not mean at runtime. To make this a compiler error you can rename the target functions and calls to them will give errors. Perhaps wrapping the two implementations in separate namespaces would make each call more explicit.
no i'm not trying to do this at runtime. i'm trying to remove a chunk of code and replace it with a more efficient version. but to do this i need to be able to find what other parts of the code are trying to access it. i'm no where even near the stage of compiling anything yet.