template<class T>
class shared_ptr
{//普通智能指针 类的对象具有指针的功能
T& operator*() const {//只返回不改变加const
return *px;
}
T& operator->() const {
return px;
}
shared_ptr(T* p):px(p){}//构造函数
};
struct Foo
{
void method(void){};
};
shared_ptr<Foo> sp(new Foo)
Foo f(*sp);
sp->method();
//迭代器智能指针
T& operator*() const
{
return (*Node).data;//Node为链表节点
}
T* operator->() const
{
return &(operator*());
}
list<Foo>::iterator ite;
*ite;
ite->method();
普通智能指针和迭代器智能指针
最新推荐文章于 2022-11-03 23:20:47 发布