what?

智能指针是基于RAII思想的c++类(类模板)

why?

智能指针帮助c++使用者更好的管理内存

how?

使用方法

eg:

std::shared_ptr<int> foo = std::make_shared<int> (10);
// same as:
//std::shared_ptr<int> foo (new int(10));

std::cout << "*foo: " << *foo << std::endl;

eg:

class A {
public:
    A(int i) : m_i(i) { }

    void foo() {
        std::cout << m_i << std::endl;
    }
private:
    int m_i;
};

typedef std::shared_ptr<A> A_PTR;

A_PTR aPtr = std::make_shared<A>(10);
std::cout << aPtr->foo() << std::endl;