Global variables and scope - C++

前端 未结 4 542
北荒
北荒 2021-01-01 02:57

I am having small problem in making a global variable works. I am using Visual Studio 2008 and standard C++.

I have two projects, one is a static library and second

4条回答
  •  误落风尘
    2021-01-01 03:49

    With the "extern" keyword, you're telling the compiler that the actual variable exists somewhere else. You should also create a variable with the same name without the extern, in one and only one place. Ordinarily you'll get an error from the linker if you define two of them, but if one's in the library and one's not it might not figure it out.

    Edit: make sure global.cpp is only in the library or test program, not both.

提交回复
热议问题