How can I get the position where my object was actually inserted?
#include <vector>
using namespace std;
vector<SomeClass> list;
SomeClass object;
list.push_back(object);
list[...].method(); // I do not have the key
Unfortunately push_back does not return anything since its return type is void.
If
vis your vector, the following will give you the position (that is, the index):Or you can look at the
size()before callingpush_back(). Then you won’t need to subtract one.