Boost logo

Boost :

Subject: Re: [boost] shared_ptr<>: why no operator[] ?
From: Neil Groves (neil_at_[hidden])
Date: 2011-07-27 04:49:11


On Tue, Jul 26, 2011 at 11:39 PM, dgwsoft <gareth_at_[hidden]> wrote:

> boost::shared_ptr<int> p(new int(42));
>
> To access elements of the array I can do:
>
> p.get()[10] = 7;
>
> But wouldn't it be nicer to do:
>
> p[10] = 7; // ?
>
> So: why is no T& operator[](int) defined for shared_ptr ? I'm just
> interested in the design reasons for this.
>
>
This isn't guaranteed to properly destroy the array. It will call delete,
rather than delete[].
This is why there is also boost::shared_array which is what you should be
using and has an operator[].
 I hope this helps.

Regards,
Neil Groves


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk