参考:智能指针详细解析
简单的应用例子:
#include <iostream>
#include <vector>
class Person
{
public:
void test()
{
std::cout << "just test unique_ptr" << std::endl;
}
private:
int my_age = 12;
};
// 智能指针使用示例
int main()
{
std::unique_ptr<Person> my_ptr(new Person());
my_ptr->test();
return 0;
}
输出:
just test unique_ptr
推荐阅读:C++ 静态成员的使用