I tried this however received the error "Variable myVar is not within scope at line blah blah in file blah blah.....".
essentially, in a boiled down form my code is as follows:
main.cpp
Contains:
#include "file1.h"
int myVar = 0;
file1.cpp
contains:
#include "file1.h"
void myFunction(){
myVar++;
}
I then compile these into a single binary.
So my question is this: Does file1.h need to include main.cpp in order to access its globally defined variable? If not then what is the problem? To me, including my main.cpp file which contains my main(), just for 1 variable, would seem like super bad programming practice.

New Topic/Question
Reply




MultiQuote







|