auto_ptr.cpp

来自「C++中只能指针的基本应用」· C++ 代码 · 共 32 行

CPP
32
字号
#include <iostream> 
#include <memory> 
using namespace std; 

class A 
{ 
public: 
	A(int a) : m_iData(a)
	{
	}; 

	void print()
	{
		cout << this->m_iData << endl;
	} 
private: 
	int m_iData; 
}; 

void smart() 
{ 
	auto_ptr<A> m_pSmartA(new A(2)); 
	m_pSmartA->print(); 
	auto_ptr<A> m_pSmartA1(m_pSmartA); 
	m_pSmartA1->print(); 
	m_pSmartA->print(); 
}; 

void main() 
{ 
	smart(); 
} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?