继承体系之间的转换操作: class Top{ ... }; class Middle:public Top{...}; class Bottom:public Middle{...}; Top* top1 = new Middle; //将Middle*转换为Top* Top* top2 = new Bottom; //将Bottom*转换为Top* const Top* const_top2 = top1; //将Top*转换为const Top* 这种情况如何运用在template上? template <typename T> class SmartPtr{ public: template <typename U> SmartPtr(const SmartPtr<U>& other) :held_ptr_( other.get() ){...} //这里就完成子类向父类的隐式转换过程. T* get()const{ return held_ptr_;} ... private: T* held_ptr_; //这是SmartPtr持有的内置指针. }; shared_ptr上的应用: template<class T> class shared_ptr{ public: shared_ptr(shared_ptr const& r); //copy 构造函数 template<class Y> shared_ptr(shared_ptr<Y> const& r); //泛化的copy构造 shared_ptr& operator=(shared_ptr const& r); //copy assignment template<class Y> shared_ptr& operator=(shared_ptr<Y> const& r); //泛化copy assignment ... };