I'm currently learning CPP and am trying to get my head round including other files into my main file.
The example below is just me messing around with the code to try and get my head around how it all works before I move onto learning the next section of the tutorial.
In file 1 I have the following code...
1 2 3 4 5 6 7 8 9 10 11
int add(int x, int y); //forward declaration using function prototype
cout << "The sum of 3 and 4 is: " << add(3, 4) << endl;
In file 2 I have...
1 2 3 4 5 6
int add(int x, int y)
return x + y;
Now, I'm trying to understand how file 1 knows to include file 2.
Would I be right to say that there is something in the stdafx.h file that acts as a bridge/link between the 2 files to make them act as 1 large file? Does stdafx.h do the same thing as me creating a 'file2.h' and including that in file1.cpp?
MS VS deals with projects. As i have understood you added file 2 to your project. The compiler compiles the files separatly. But then the lonker tries to resolve an external symbol (in your case this external symbol is add) it looks through modules you added to the project.