Reputation: 4771
I am not really sure what this line of code does.
vector<vector<A>> someth;
Does this mean that creates a vector with elements vectors with objects of class A? Can please someone explain this?
Thanks
Upvotes: 3
Views: 4728
Reputation: 522
Correct. Basically
someth[i]
returns a vector. And
someth[i][j]
returns an A.
One thing needs to pay attention to is that there must be a space between two '>'s. Should be
vector<vector<A> > someth;
Upvotes: 3
Reputation: 49177
yes, that's exactly what it means, it's a vector of vectors of A's.
Upvotes: 1
Reputation: 4953
Yes, this creates a vector whose elements are vectors whose elements are A objects. It's worth noting that this declaration is only valid in C++11. Before then, the >>
was interpreted as the symbol >>
(read from). It needs to be declared vector<vector<A> > someth;
(with a space).
Upvotes: 4
Reputation: 258548
Yes.
Also note that your syntax is not supported before C++11:
vector<vector<A> > someth;
is the pre-C++11 syntax. Before that, >>
was treated as the bit-shift operator, so you'd get a compiler error on some compilers.
This actually creates an empty vector
that can contain objects of type vector<A>
.
Upvotes: 8