how to detele auto pointer?
-
hi, all does anybody know when should be release the auto pointer? thanks! m_pdbf = std::auto_ptr( new CBNoMessageBox_DBF_NTX( pszFileName ) );
That's not the way to use a
std::auto_ptr
. Do like this:std::auto_ptr msgbox(new CBNoMessageBox_DBF_NTX(pszFileName));
msgbox->SomeMemberFunctionOfCBNoMessageBox_DBF_NTX();valerie99 wrote: does anybody know when should be release the auto pointer? Normally - never, since the allocated memory is deleted by
std::auto_ptr
at scope exit. But if you must, thenstd::auto_ptr<>::release()
is your friend. -- The Blog: Bits and Pieces -- modified at 18:10 Monday 26th September, 2005 -
hi, all does anybody know when should be release the auto pointer? thanks! m_pdbf = std::auto_ptr( new CBNoMessageBox_DBF_NTX( pszFileName ) );
The autopointer deletes its associated object when it goes out of scope automatically. To destroy it sooner, call reset(). -- Keep talking! You're the fool, I'm the preacher.
-
That's not the way to use a
std::auto_ptr
. Do like this:std::auto_ptr msgbox(new CBNoMessageBox_DBF_NTX(pszFileName));
msgbox->SomeMemberFunctionOfCBNoMessageBox_DBF_NTX();valerie99 wrote: does anybody know when should be release the auto pointer? Normally - never, since the allocated memory is deleted by
std::auto_ptr
at scope exit. But if you must, thenstd::auto_ptr<>::release()
is your friend. -- The Blog: Bits and Pieces -- modified at 18:10 Monday 26th September, 2005Johann Gerell wrote: That's not the way to use a std::auto_ptr There can be a good reason for this. Suppose the auto_ptr was declared as a class member and not initialized in the constructor of the class. I have done this from time to time. John