STL---auto

xiaoxiao2021-02-28  87

#include<iostream> using namespace std; template<class T> class auto_ptr1 {         public:                 explicit auto_ptr1(T* p =0 ):pointee(p){ cout<<"p..\n";}                 template<class U>                 auto_ptr1(auto_ptr1<U>&rhs):pointee(rhs.release()){cout<<"rhs..\n";}                 ~auto_ptr1()                 {                         cout<<"~\n";                         delete pointee;                 }                 template<class U>                 auto_ptr1<T>& operator=(auto_ptr1<U>&rhs)                 {                         cout<<"=\n";                         if(this != &rhs)                                 reset(rhs.release());                         return *this;                 }                 T& operator*()const                 {                         cout<<"*\n";                         return *pointee;                 }                 T* operator->()const                 {                         cout<<"->\n";                         return pointee;                 }                 T* get()const                 {                         return pointee;                 }                 //...         private:                 T* pointee; }; void test() {         auto_ptr1<string> ps (new string("jjhou"));         cout<<*ps<<endl;         cout<<ps->size()<<endl; } int main() {         test(); }
转载请注明原文地址: https://www.6miu.com/read-53052.html

最新回复(0)