2013年7月20日

摘要: 只能指针实现了指针指向对象的共享。同时避免了悬垂指针等问题。通过对运算符的重载它可以像普通指针一样的操作。只要有一个智能指针指向这个对象,那么这个对象就不会被释放掉。#include#include#include#include#includeusing namespace std;// 引用计数实现智能指针templateclass U_Ptr{ size_t use; T *ip; U_Ptr(T *p):ip(p),use(1){} template friend class HasPtr; ~U_Ptr(){delete ip;}};templat... 阅读全文
posted @ 2013-07-20 13:47 dyc0113 阅读(146) 评论(0) 推荐(0) 编辑
摘要: #include#include#include#include#includeusing namespace std;struct Exmpl{ Exmpl() { std::cout<<"Exmpl()"<<endl; } Exmpl(const Exmpl &) { cout<<"Exmpl( const Exmpl&)"<<endl; } Exmpl& operator=(const Exmpl &rhe) { cout<<"operator=( 阅读全文
posted @ 2013-07-20 11:37 dyc0113 阅读(183) 评论(0) 推荐(0) 编辑

导航