I'm having a little problem creating a global variable. I am using Visual Studio 2008 and standard C ++.
I have two projects, one is a static library, and the second is a test program that uses this library. I have a global variable in global.h, for example
#ifndef GLOBAL_H #define GLOBAL_H #include <string> extern std::string globalWord; #endif // GLOBAL_H!
I have global.cpp where I initialize this variable. This variable is used inside my library project. I set the value of this variable from a test project, but this value is not reflected in the library project.
I debugged and shows the new value in the test project, but when the control reaches the library project, this variable value shows empty. So this global range of variables is limited only by the project in which it belongs?
Or is there a better way to do this? I do not want to change the parameters of my function or constructor in my library in order to pass this value.
Any help would be great.
Edit:
This is how this variable is declared in global.cpp
#include <string> #include "../global.h" std::string globalWord = "";
This is how I used it in my library
#include "../global.h" string text = globalWord;
thanks
source share