提交 2337187e 编写于 作者: 邹晓航

bug fix

上级 525308f2
......@@ -107,20 +107,22 @@ namespace TinySTL{
class shared_ptr{
public:
typedef T element_type;
private:
template<class Type>
using ref_t = Detail::ref_t < Type >;
public:
explicit shared_ptr(T *p = nullptr) :ref_(new ref_t<T>(p)){}
template<class D>
shared_ptr(T *p, D del) : ref_(new ref_t<T>(p, del)){}
shared_ptr(const shared_ptr& sp){
ref_ = sp.ref_;
++(*ref_);
copy_ref(sp.ref_);
}
shared_ptr& operator = (const shared_ptr& sp){
if (this != &sp){
decrease_ref();
ref_ = sp.ref_;
copy_ref(sp.ref_);
}
return *this;
}
......@@ -136,16 +138,17 @@ namespace TinySTL{
operator bool() const{ return get() != nullptr; }
private:
void decrease_ref(){
if (ref_){
if (ref_->get_data()){
--(*ref_);
if (use_count() == 0)
delete ref_;
}
}
void copy_ref(ref_t<T> *r){//ȷĿref_t
ref_ = r;
++(*ref_);
}
private:
template<class Type>
using ref_t = Detail::ref_t < Type > ;
ref_t<T> *ref_;
};
template<class T1, class T2>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册