Serg
Serg

Reputation: 14098

C++, Modifying vector elements using its pointer

I wish to avoid switch statement by defining a pointer to a vector. I need help to use insert and erase methods.

bool selectFirst = true;
std::vector<int> v1, v2;
std::vector<int> *v = selectFirst ? &v1 : &v2;
v->push_back(0);

But how to insert or erase values from v ???

Thank you

Upvotes: 0

Views: 408

Answers (1)

Diego Sevilla
Diego Sevilla

Reputation: 29001

Well, the same way you used push_back, you can use erase... Look at the documentation for those operations in the STL. For example, deleting the first element:

v->erase( v->begin() );

Upvotes: 2

Related Questions