From: Albrecht Fritzsche (albrecht.fritzsche_at_[hidden])
Date: 2001-07-17 10:06:53
the behaviour is "correct", but not your usage of the std::vector,
so to say ;-)
Marco Morandini wrote:
> std::vector<boost::shared_ptr<int> >a;
Here you allocate (reserve) raw storeage large enough to hold 8
elements. Nothing more, nothing less.
Here you would have resized the vector to a memory large enough
to hold 8 elements and all elements would have been default initialized
to boost::shared_ptr<int>(). The effect would have been like
a.insert(a.end(), 8, boost::shared_ptr<int>());
since a was still empty, ie a.size() == 0 before that call (resize
changes only the capacity, not the size).
> int * y;
> y = new int;
> a = boost::shared_ptr<int>(y);
Here you try now to access uninitialized memory...
-- Albrecht Fritzsche, Software Developer alfabet meta-modeling AG, leibnizstr. 53, 10629 berlin, germany http://www.alfabet.de
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk