设为首页 加入收藏

TOP

C++的一个简单的句柄类模板
2015-07-20 18:04:48 来源: 作者: 【 】 浏览:2
Tags:一个 简单 模板
#ifndef HANDLE_H
#define HANDLE_H 
#include "Animal.h"

template 
  
   
class Handle{
    public:
        Handle(T *ptr);
        Handle(const Handle &other);
        Handle &operator = (const Handle &other);
        ~Handle();
        T *operator->();
    private:
        T *ptr_;
};

template 
   
     inline Handle
    
     ::Handle(T *ptr) :ptr_(ptr->copy()) {} template 
     
       inline Handle
      
       ::Handle(const Handle &other) :ptr_(other.ptr_->copy()) {} template 
       
         inline Handle
        
          &Handle
         
          ::operator = (const Handle &other) { if(this != &other){ delete ptr_; ptr_ = other.ptr_->copy(); } return *this; } template 
          
            inline Handle
           
            ::~Handle() { delete ptr_; } template 
            
              inline T *Handle
             
              ::operator -> () { return ptr_; } #endif /*HANDLE_H*/
             
            
           
          
         
        
       
      
     
    
   
  

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇iframe笔记及获取根目录的方法 下一篇HDU 4869 Turn the pokers(推理)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: