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 throwsrequirements:
tshould 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
Post a Comment