Boost 智能指针可以与多态一起使用,但是如何将子类转换回指针呢?
using namespace boost;
// ...
shared_ptr<SuperClass> a_ptr(new SubClass);
// ...
shared_ptr<SubClass> b_ptr = (shared_ptr<SubClass>)a_ptr; // Doesn't compile
最后一行没有编译并给出error C2440: 'type cast' : cannot convert from 'boost::shared_ptr
<T>
' to 'boost::shared_ptr<T>
'