Dear All,
I have a question regarding to linking separate files for compilation.
For example, I have two file in the same directory: file1.cpp & file2.cpp.
==> file1.cpp <==
int iNumber= 999;
==> file2.cpp <==
#include <iostream>
using namespace std;
extern int iNumber;
int main()
{
cout << "iNumber= " << ::iNumber << endl;
return 0;
}
In file2, the variable iNumber cannot be seen. I thought file1.cpp
int iNumber=999;
makes the variable iNumber in file scope, and "extern int iNumber;"
statement tells file2.cpp that iNumber has been specified somewhere
else, therefore iNumber should be able to be printed out in file2.cpp.
But it cannot. What is missing? Is a "include" statement? How to add it?
Thank you very much.