I don't think so, the only diference between struct and class is the
default access level -- private in classes, public in structs. As Ivan
said, don't expect a std::vector to be decreasing its capacity, the
standard only requires the erase methods to call destructors and
invalidate the items in the array. This is what it says:
iterator erase(iterator position);
iterator erase(iterator first, iterator last);
Effects:
Invalidates all the iterators and references after the point of the
erase.
Complexity:
The destructor of T is called the number of times equal to the num-
ber of the elements erased, but the assignment operator of T is
called the number of times equal to the number of elements in the
vector after the erased elements.
In fact, if std::vector reallocated the data on erase, it wont meet the
complexity requeriments set by the standard. Check other containers in
the STL if you really need that.
> De: gam...@li...
> [mailto:gam...@li...] En
> nombre de Colin Fahey
> Enviado el: Thursday, November 07, 2002 2:05 PM
> Para: GDWindows
> Asunto: Re: [GD-Windows] memory leak?
[..]
> [A] Best guess: You are doing "new" and "delete"
> on a regular "struct", instead of a "class".
> This may simply allocate raw bytes with the
> same size as your structure. This means that
> the "std::vector<float> array" member is NOT
> CONSTRUCTED, but is simply given space to exist.
> Even though C++ compilers may implement
> "struct" as "class", I don't know if "new" will
> CONSTRUCT members of a "struct".
> Anyhow, I'm guessing that the "delete" calls
> aren't calling the destructor of the "array"
> object within the "struct" (TestObj).
[..]
Diego
|