您的位置:首页 > 编程语言 > C语言/C++

C++智能指针类模板实例

2015-08-21 09:03 295 查看
#ifndef MYCLASS_H_

#define MYCLASS_H_

class myclass

{

public:

myclass();

~myclass();

};

#endif

#include"myclass.h"

#include<iostream>

using namespace std;

myclass::myclass()

{

cout << "对象生成了!"<< endl;

}

myclass::~myclass()

{

cout << "对象释放了!"<< endl;

}

// SmartPoint.cpp : Defines the entry point for the console application.

//智能指针类模板 2015年8月20日10:57:25

#include<iostream>

#include<memory>

#include"myclass.h"

using namespace std;

int main(int argc, char argv[])

{

//-------------------------------------------

{

cout << "智能指针1:\n------------------" << endl;

auto_ptr<myclass> p1(new myclass);

//智能指针1

}

{

cout << "\n智能指针2:\n------------------" << endl;

auto_ptr<myclass> p2(new myclass);

//智能指针2

}

//------------------------------------------------

cout << "Test is Successful!!" << endl;

cin.get();

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: