A smart pointer is an abstract data type that stimulates a pointer with additional funationality, such as auto memory deallocation, reference counting, etc. In practise it could be a wrapper around of a regular pointer and forwards all meaningfull operations to the pointer

The simplest smart pointer is autr_ptr which are defined in header file <memory>

 

template <class T> auto_ptr {

public:
    explicit auto_ptr(T* p): auto_ptr(p){}
     ~auto_prt() {delete ptr;}
    T& operator*(){return *ptr;}
    T* operator->(){return &ptr;}
private: 
    T*  ptr;
    // other functionalities...
};

 

 

 

 

reference:

- http://en.wikipedia.org/wiki/Smart_pointer

- http://ootips.org/yonat/4dev/smart-pointers.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-03
  • 2021-08-31
  • 2022-03-10
  • 2022-01-22
  • 2021-08-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
  • 2021-11-10
  • 2021-08-27
  • 2021-09-01
  • 2022-12-23
相关资源
相似解决方案