Hello
I want to pass a bidimensional vector to the constructor of all instances of MyClass
. All instances must use and share and modify the same vector. And I want to keep a reference to that main_vector
to use it later in the program
I am passing it by reference to MyClass. The problem is that when I assign it to ref_to_main_vector
to use it later, I'm not saving the reference but creating a duplicate of it, so each instances has its own copy.
How can I make them all share the same variable? I'm not interested in passing it by a specific method, but this is the only way that I have been able to make it partially work
Thanks
marc
std::vector < std::vector< int > > ref_to_main_vector;
MyClass::MyClass( std::vector < std::vector< int > > & m_v){
ref_to_main_vector = m_v;
}
void MyClass::update(){
ref_to_main_vector.resize(3);
ref_to_main_vector[2].resize(3);
...
}
///////////
int main( ){
std::vector < std::vector< int > > main_vector;
MyClass temp = new MyClass(main_vector);
temp.update();
return 0;
}