Reputation:
I just saw in a tutorial someone who used in the same file both:
myVector.back().push_back();
myVector.push_back();
What's the difference?
Upvotes: 0
Views: 141
Reputation: 117856
The first had to be something like
vector<vector<T>>
Otherwise it would not work. back()
returns the element at the back of the vector
. When you say
myVector.back().push_back();
it would be accessing the last vector<T>
, then calling push_back()
on that inner vector
If it is the case that myVector
is a vector<vector<T>>
, then
myVector.push_back();
would be pushing back an empty vector<T>
whereas
myVector.back().push_back();
would be pushing back a default T
onto the last vector<T>
in myVector
.
Upvotes: 5