-
You can use resize() even if the class does not have
a default constructor.
Code:
v.resize(100,MyClass(1,0,"hello world"));
// or even better, if you know the size at creation time
vector<MyClass> v(100,MyClass(1,0,"hello world"));
of course, if the constructor is expensive and
you are just going to over-write the values anyway,
then reserve() and push_back() would still be faster.
-
Ah, yes, I'd forgotten that overload of resize (the curse of Symbian: you get rusty on STL because you're not allowed to use it). Still, as you say, unless that's what you really want (100 identical copies), reserve() and push_back() probably make more sense, from a readability point of view if nothing else.