I have a vector in a DLL visual studio project that i would like to use in my executable project and another DLL. I want the all projects to be using the same instance of the vector. I dont want each project to create their own instance. How can i do this?
// DLL A project
// A.h
extern std::vector<int> ids;
// A.cpp
std::vector<int> ids;
// DLL B project
// B.h
void foo();
// B.cpp
#include "A.h"
void foo()
{
ids.push_back(2);
}
// executable project
// main.cpp
#include "A.h"
#include "B.h"
int main()
{
foo();
ids.push_back(1);
// should print 21
for(auto i : ids)
{
std::cout << i << std::endl;
}
return 0;
}