arrays - Why can't boost::shared_ptr dereference a T[] -


i noticed when writing following code

boost::shared_ptr<int[]> ptr(new int[5]); int* deref = *ptr; 

that boost::shared_ptr<t>::operator*() requires t not array type.

t & operator*() const; // never throws

requirements: t should not array type. stored pointer must not 0.

returns: reference object pointed stored pointer.

throws: nothing.

the compiler error (rightly) produced viewable here

std::shared_ptr<t>::operator*() on other hand makes no such requirement, shared_ptr doesn't seem constructible t[] or t*

this of course can remedied using scoped/shared_array instead of smart pointer array, or if nothing else using std::vector.

but doesn't explain why shared_ptr couldn't have operator*() specified return t* when t array.

can shed light on why t[] handled specially in boost::shared_ptr?


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -