Auto

xiaoxiao2021-03-06  65

Appendix: Auto_PTR's implementation code, from Nicolai M. Josuttis

/ * Class auto_ptr * - improved standard conforming implementation * / namespace std {// auxiliary type to enable copies and assignments (now global) template struct auto_ptr_ref {Y * yp; auto_ptr_ref (Y * rhs): yp (rhs ) {}}; template class auto_ptr {private: T * ap; // refers to the actual owned object (if any) public: typedef T element_type; // constructor explicit auto_ptr (T * ptr = 0) throw (): AP (PTR) {} // Copy Constructors (with Implicit Conversion) // - NOTE: NONCONSTANT Parameter Auto_Ptr (Auto_Ptr & RHS) Throw (): AP (RHS.RELEASE ()) {} Template auto_ptr (AUTO_PTR & RHS) throw (): AP (RHS.RELEASE ()) {} // Assignments // - NOTE: NONCONSTANT Parameter Auto_Ptr & Operator = (Auto_PTR & RHS) throw () {RESET ( RHS.RELEASE ()); Return * this;} Template auto_ptr & operator = (auto_ptr & r Hs) throw () {reset (rhs.release ()); return * this;} // destructor ~ auto_ptr () throw () { Delete ap; AP;} // Release Ownership T * Release () throw () {t * tmp (AP); AP = 0; Return TMP;

转载请注明原文地址:https://www.9cbs.com/read-110874.html

New Post(0)