星期三, 3月 14, 2012

C++11: make_shared<T>()

Sample:

#include <memory>
#include <iostream>

using namespace std;

class MyClass{
public:
int m_i;
MyClass(int i):m_i(i){  cout << "constructor" << endl;
}
~MyClass(){
cout << "destructor" << endl;
}
};

void _tmain(int argc, _TCHAR* argv[])
{
cout << "enter main" << endl;
auto a = make_shared<MyClass>(10);
cout << a->m_i << endl;
cout << "leave main" << endl;
}


output:



enter main

constructor

10

leave main

destructor