开发者

Using extern variables in visual studio 2010

开发者 https://www.devze.com 2023-04-07 16:44 出处:网络
I tried defining int GlobalVariable; in FileA.cpp and inside FileB.cpp, I tried to use GlobalVariable by de开发者_JAVA百科claring

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消