Using extern variables in visual studio 2010
I tried defining
int GlobalVariable;
in FileA.cpp
and inside FileB.cpp, I tried to use GlobalVariable by de开发者_JAVA百科claring
extern int GlobalVariable;
but when I tried using GlobalVariable, I get 'GlobalVar' : undeclared identifier or some unresolved linking error, how do I go about making it work?
(Without having your code) Use this pattern:
FileA.h
extern int GlobalVariable;
FileA.cpp
int GlobalVariable = 1000;
First of all, you're defining a variable called GlobalVariable
but in the error message the variable GlobalVar
is mentioned. Make sure that you don't accidentally get the name wrong.
That being said, are you sure that FileA.cpp
is compiled into whatever module FileB.obj
(the object file generated from FileB.cpp
) is built into?
精彩评论