29 lines
377 B
C++
29 lines
377 B
C++
//
|
|
// Created by dongl on 22-9-28.
|
|
//
|
|
|
|
#ifndef MSTL_SHARED_PTR_H
|
|
#define MSTL_SHARED_PTR_H
|
|
|
|
#endif //MSTL_SHARED_PTR_H
|
|
|
|
/// 智能指针 像一个指针
|
|
template<class T>
|
|
class shared_ptr{
|
|
public:
|
|
T& operator*() const {
|
|
return *px;
|
|
}
|
|
|
|
T* operator->() const {
|
|
return px;
|
|
}
|
|
|
|
shared_ptr(T* p) : px(p) {}
|
|
private:
|
|
T* px;
|
|
long* pn;
|
|
};
|
|
|
|
|