I have such problem: I have class Foo
, and if have some objects of this class,
Foo a();
I need to put this object to 2 differ
You need a vector of references. And since you specify that you need to use std::vector, then the correct thing to do is wrap your objects in the std::reference_wrapper
. This page from C++ reference should explain it nicely:
vector> vA, vB;
vA.push_back(a);
vB.push_back(a); // puts 'a' into both vectors
// make changes to 'a'
// use .get() to get the referenced object in the elements of your vector
// vA[0].get() == vB[0].get()