I am working on a small project that has two modules and a header file.
In one of my modules I create a vector of strings and populate it with some data.
I am now having problems with accessing the vector values in my other module. could anyone offer me any advice on how to make this global?
Please don’t think I am lazy/not tried sorting this myself, i am just confused with #ifndef’s, #includes, #define, extern’s and when/where to declare function prototypes. I know all these have something to do with it, just not sure about the order! I am using VS 2010.
Define an API function in your module which returns a reference to your vector and use that function in your other modules.
file1.hfile1.cppSo, in the other module (
file2.cpp) you just:Hopefully, you don’t want to use it in a multithreaded environment, otherwise you would need to implement it as a proper singleton.