Re: Vector and derived classes objects
From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 11/08/04
- Next message: Alexander Terekhov: "Re: Inheriting from STL bitset"
- Previous message: Pete Becker: "Re: Inheriting from STL bitset"
- In reply to: ma740988: "Re: Vector and derived classes objects"
- Next in thread: ma740988: "Re: Vector and derived classes objects"
- Reply: ma740988: "Re: Vector and derived classes objects"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 08 Nov 2004 10:30:10 -0500
ma740988 wrote:
> [...]
> Since I am using just vector of pointers, the copy-ctor or assign-op
> wont be called for the objects the pointer points to, hence I dont see
> any way an exception can be thrown there with my push_back.
Huh? push_back beyond the capacity of the vector _requires_ that the
storage for that vector is grown. That means reallocation. That also
means the original storage has to stay around until all the copying
has competed. If your vector occupies at least half the memory that
your process is allowed to have, there is no way in hell push_back can
succeed without throwing to tell you that you've run out of memory.
> Bottom line as I understand it:
> If you dont provide your own allocator class, the push_back of
> std::vector is a no-op on failure. It wont throw any exception if it
> fails, Josuttis as also mentiones that in his STL book.
I think you got this wrong. _If_ the push_back throws (to indicate the
failure), _then_ it's a NOP. IOW, the container doesn't change, all
iterators are valid, no reallocation happens. Reread that place in
Josuttis' book. I am 101% certain that all he writes there is the repeat
of 23.1/10. Just think a little: how can the push_back fail and _not_
throw an exception?
V
- Next message: Alexander Terekhov: "Re: Inheriting from STL bitset"
- Previous message: Pete Becker: "Re: Inheriting from STL bitset"
- In reply to: ma740988: "Re: Vector and derived classes objects"
- Next in thread: ma740988: "Re: Vector and derived classes objects"
- Reply: ma740988: "Re: Vector and derived classes objects"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|