📄 cppmisc_details.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <meta name="generator" content="HTML Tidy for Linux/x86 (vers 1st October 2002), see www.w3.org"> <title>Miscellaneous C++</title> </head> <body bgcolor="#ffffff"> <table width="100%" bgcolor="#eeeeff"> <tr> <td><a href="index.html">cppreference.com</a> -> <a href="cppmisc.html">Miscellaneous C++</a> -> Details</td> </tr> </table> <h1>Miscellaneous C++</h1> <hr> <h2><a name="auto_ptr">auto_ptr</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include<memory> auto_ptr<class T> name</pre> </td> </tr> </table> <p> The auto_ptr class allows the programmer to create pointers that point to other objects. When auto_ptr pointers are destroyed, the objects to which they point are also destroyed. The auto_ptr class supports normal pointer operations like <i>=</i>, <i>*</i>, and <i> -></i>, as well as two functions <i>T* get()</i> and <i>T* release()</i>. The <i>get()</i> function returns a pointer to the object that the auto_ptr points to. The <i>release()</i> function acts similarily to the <i>get()</i> function, but also relieves the auto_ptr of its memory destruction duties. When an auto_ptr that has been released goes out of scope, it will not call the destructor of the object that it points to. </p><pre> #include <memory> using namespace std; class MyClass { public: MyClass() { // nothing } ~MyClass() { // nothing } void myFunc() { // nothing } }; int main() { auto_ptr<MyClass> ptr1(new MyClass), ptr2; ptr2 = ptr1; ptr2->myFunc(); MyClass* ptr = ptr2.get(); ptr->myFunc(); return 0; }</pre> <br> <br> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -