Goal: "Backing up" a vector X referenced in variable A into another variable B. Assigning a new vector Y to variable A. Use variable B to work with vector X.
std::vector<T*> vector_(10);
std::vector<T*> *vector_old = &vector_;
std::vector<T*> vector_new(20);
cout << &vector_ << endl;
cout << vector_old << endl;
cout << &vector_new << endl;
cout << (*vector_old).size() << endl;
vector_ = vector_new;
cout << (*vector_old).size() << endl;
Output:
1: 0x7fff5316fb18
2: 0x7fff5316fb18
3: 0x7fff5316e940
4: 10
5: 20
I expect line 5 to be 10. Why is it 20?
Hint: Please feel free to change the title...
Aucun commentaire:
Enregistrer un commentaire