C++11标准库中的shared_ptr两种方式
- 直接调用构造函数
- make_shared
直接调用构造函数
#include <iostream>
#include <memory>
using namespace std;
class B{
public:
CTest ct;
char b;
~B(){
cout<<"~B executed"<<endl;
}
};
class C : public B{
public:
~C(){
cout<<"~C executed"<<endl;
}
};
int main()
{
B *bb = new C;
shared_ptr<B> p(new C);
shared_ptr<B> p2(bb);
return