⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 auto_ptr.h

📁 ears-0.32, linux下有用的语音信号处理工具包
💻 H
字号:
#ifndef Heap_ptr_h#define Heap_ptr_h#include <assert.h>template <class T> class auto_ptr { public:   auto_ptr(T* p=0)              { p_=p; }   ~auto_ptr()                   { delete p_; }  auto_ptr<T>& operator= (T* p) { delete p_; p_=p; return *this; }  T* operator->() { assert(p_!=0); return p_; }  T& operator* () { assert(p_!=0); return *p_; }private:   T* p_;  auto_ptr<T>& operator= (const auto_ptr<T>&);  auto_ptr               (const auto_ptr<T>&);};#if 0// Shamelessly stolen from the excellent 'C++ FAQs' by Cline/Lomow// and Meyers' 'More Effective C++'.#include <stdlib.h>#include <assert.h>template <class T>class auto_ptr{public:  auto_ptr (T* ptr = 0)   { ptr_=ptr; }  ~auto_ptr()      { deallocate(); }  void deallocate { delete ptr_;  ptr_ = 0; }  auto_ptr<T>& operator= (T* ptr)  { deallocate(); ptr_=ptr; return *this; }    T* operator->() { assert(ptr_!=0); return _ptr; }  T& operator* () { assert(ptr_!=0); return *_ptr; }    T* relinquishOwnership()  { T* old = ptr_;  ptr_=0;  return old; }  private:  T* ptr_;  auto_ptr<T>& operator= (const auto_ptr<T>&);  auto_ptr               (const auto_ptr<T>&);};#endif#endif

⌨️ 快捷键说明

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