C++编程(C)

throw yunexpected0 networkexception beijing

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: / p指向一个矩形 auto_ptr<Shape> pbox(pb); p->rotate(45); // auto_ptr<Shape>的使用与Shape*一样 // ... if(in_a_mess) throw Mess(); } // 记住,退出时需要删除pb Beijing University of Posts & Telecommunications Beijing young@buptnet.edu.cn auto_ptr 为了获得这种所有权语义(ownership semantics),也常被称为破坏性复制语义 (destructive copy semantic), auto_ptr具有与常规指针很不一样的复制 语义:在将一个auto_ptr复制给另一个之 后,原来的auto_ptr将不再指向任何东西 因为复制auto_ptr将导致对它自身的修 改,所以const auto_ptr就不能复制 Beijing University of Posts & Telecommunications Beijing young@buptnet.edu.cn auto_ptr的声明 // auto_ptr在<memory>中声明 template<class X> class std::auto_ptr{ template<class Y> struct auto_ptr_ref{/*...*/}; // 协助类 X* ptr; public: typedef X element_type; explicit auto_ptr(X* p=0) throw(){ptr=p;} // throw()表示...
View Full Document

Ask a homework question - tutors are online