1、分析下面代码,说出问题所在
#include <bits/stdc++.h> using namespace std; class A{ public: A(){}; A(int a): age(a) {}; ~A(){}; private: int age; }; int main() { A *a = new A(10); shared_ptr<A> p1(a); shared_ptr<A> p2(a); }
a被复制给shared_ptr两次,在这两个shared_ptr中它们的引用计数都是1,所以在结束时a会被释放两次。
标签:int,age,智能,shared,ptr,指针 From: https://www.cnblogs.com/fei1013/p/17281298.html