标签:智能指针 article memory ges use class 分享 sdn eset
#include <iostream> #include <memory> using namespace std; int main(int argc, char **argv) { // shared_ptr<int> sp(new int(10)); shared_ptr<int> sp = make_shared<int>(10); cout << sp.use_count() << " " << *sp << endl; shared_ptr<int> sp2 = sp; cout << sp2.use_count() << " " << *sp2 << endl; sp2.reset(); cout << sp.use_count() << " " << *sp << endl; weak_ptr<int> wp = sp; cout << wp.use_count() << " " << endl; sp2 = wp.lock(); cout << sp2.use_count() << " " << *sp2 << endl; sp.reset(); cout << wp.use_count() << " " << wp.expired() << endl; sp2.reset(); cout << wp.use_count() << " " << wp.expired() << endl; }
参考资料:
标签:智能指针 article memory ges use class 分享 sdn eset
原文地址:http://www.cnblogs.com/gattaca/p/6661319.html