Boost logo

Boost :

From: Albrecht Fritzsche (albrecht.fritzsche_at_[hidden])
Date: 2001-07-17 10:06:53


Hi Marco,

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;
> a.reserve(8);

Here you allocate (reserve) raw storeage large enough to hold 8
elements. Nothing more, nothing less.

> //a.resize(8);

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[0] = boost::shared_ptr<int>(y);

Here you try now to access uninitialized memory...

Ali

-- 
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