
27 Jul
2011
27 Jul
'11
8:49 a.m.
On Tue, Jul 26, 2011 at 11:39 PM, dgwsoft <gareth@dgwsoft.co.uk> 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