我是shared_ptr的新手。我有一個關於C的語法++ 0x中的shared_ptr如下幾個問題:shared_ptr的基本語法問題
//first question
shared_ptr<classA>ptr(new classA()); //works
shared_ptr<classA>ptr;
ptr = ?? //how could I create a new object to assign it to shared pointer?
//second question
shared_ptr<classA>ptr2; //could be tested for NULL from the if statement below
shared_ptr<classA> ptr3(new classA());
ptr3 = ?? //how could I assign NULL again to ptr3 so that the if statement below becomes true?
if(!ptr3) cout << "ptr equals null";
爲什麼make_shared更好地在這裏? – 2010-12-01 09:28:24