Soy nuevo en shared_ptr. Tengo algunas preguntas con respecto a la sintaxis de C++ 0x shared_ptr de la siguiente manera:Pregunta de sintaxis básica para 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";
¿Por qué se make_shared mejor aquí? –
@Fred: separación de responsabilidad. 'make_shared <>' permite que la biblioteca maneje el 'new', por lo que su código no muestra una invocación 'new' aparentemente desequilibrada. La biblioteca hace el 'delete', por lo que debería hacer el' new' también. –
@Fred Nurk: 'make_shared' puede eliminar una asignación. – ybungalobill