My records:
1. If the Releaser is specifiedDirectCall the destructor. Because the Releaser is one. If this parameter is not specified, the Destructor is the Releaser.
2. STL smart pointers support less built-in internal types than Class: shared_ptr <char> S (New char [10]); memset (S, 0x00, 10 );//Error! Only memset (S. Get.
3. The Releaser cannot be specified for auto_ptr.
# Include "iostream" # include <tr1/memory> using namespace STD; Using STD: tr1: shared_ptr; Using STD: auto_ptr; Class C {public: C () {cout <"C ()" <Endl; Buf = new char [10];} ~ C () {cout <"~ C () "<Endl; If (BUF) {cout <"~ C () Delete [] Buf. "<Endl; Delete [] Buf ;}} static void myrelease (C * PC) {cout <" myrelease () "<Endl; cout <" myrelease () delete [] Buf. "<Endl; Delete [] PC-> Buf; PC-> Buf = NULL; cout <" myrelease () delete C: "; Delete PC; // call ~ C ().} PRIVATE: char * Buf;}; int main () {cout <"STD: tr1: shared_ptr <C >:" <Endl; {C * A = new C; shared_ptr <C> sharec (A, C: myrelease);} cout <"<-shared_ptr test ended. \ n "<Endl; cout <" STD: tr1: shared_ptr <C> copy test "<Endl; {shared_ptr <C> sharec (New C, C:: myrelease); shared_ptr <C> sharec2 = sharec;} cout <"<-shared_ptr copy test ended. \ n "<Endl; cout <" STD: auto_ptr <C>: "<Endl; C * B = new C; auto_ptr <C> AutoC (B ); cout <"Return 0;" <Endl; return 0 ;}
$ g ++ main. cpp