I have this program I’ve been working on for a while, which is basically a checkers game where somebody can either decide to play against a player or watch a computer simulation. Now both of these are basically the same code, except for the fact that the computer simulation takes randomized values. Both of these code blocks are located in my driver and I want to break up the code into two different cpp files. This way I have user input decide what is going to happen.
so for example:
if(x == 1)
call the player cpp file
else if (x == 2)
call the simulation cpp
My program is object-oriented, but I was wondering if there is a way to just run code from a different file without creating a class and defining functions?
You could do something like
And have the individual .cpp files contain the logic for each major section. This is a bit clunkier though that just wrapping the functionality in some functions and call those from your if-if-else statements. At least with functions if something goes wrong, it will be easier to debug or do stack-traces, etc. rather than chase around multiple .cpp files.