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();
}
#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();
}
相关文章推荐
- C++ Primer : 第十二章 : 动态内存之shared_ptr类
- Windows下创建动态库
- Hadoop c++开发
- C++ primer的第三章的主要内容
- C++ primer的第二章的主要内容
- C++ primer的第一章的主要内容
- 笔记 引用与赋值
- C语言的动态内存分配
- Standard C++ Episode 11
- Standard C++ Episode 10
- Standard C++ Episode 9
- Standard C++ Episode 8
- Standard C++ Episode 7
- Standard C++ Episode 6
- Standard C++ Episode 5
- 异常?C语言程序中我们如何管控(处理)运行期间的运行异常
- Standard C++ Episode 4
- 使用 cscope浏览 C++文件
- ZOJ 3674 Search in the Wiki 【C++STL大法尽情地模拟】
- C语言内存分配