b***i 发帖数: 3043 | 3 看Synopsis
template class shared_ptr {
public:
typedef T element_type;
shared_ptr(); // never throws
template explicit shared_ptr(Y * p);
~shared_ptr(); // never throws
Effects:
If *this is empty, or shares ownership with another shared_ptr instance (use
_count() > 1), there are no side effects.
Otherwise, if *this owns a pointer p and a deleter d, d(p) is called.
Otherwise, *this owns a pointer p, and delete p is called.
可见,你
boost::shared_ptr create(){
boost::shared_ptr p(new B());
return p;
}
我的理解,就是T==A, 但是Y==B,那个构造函数里p是类型B*的。
【在 X*4 的大作中提到】 : 关于boost shared_ptr的, : #include : #include : #include : class A{ : public: : virtual void sing() = 0; : protected: : virtual ~A(){ : std::cout << "dtor of base" << std::endl;
|