I’m writing some code in MFC and I want to use auto pointers. I’ve come across two different classes that look like they do the same thing: CAutoPtr and std::auto_ptr What are people’s thoughts about the two different implementations?
Further, I know there is std::tr1::shared_ptr. Is there a similar shared_ptr that is in ATL/MFC?
Both
CAutoPtrandauto_ptrgive you smart pointer semantics including transfer of ownership semantics.CAutoPtris an ATL class — built using COM. It is a non-standard extension for a particular OS.auto_ptron the other hand is standard C++. If you want to use a container of such objects you have to useCAutoPtrArrayorCAutoPtrList.An important point to note is that there is something called
auto_ptr_refthat allows you to returnauto_ptrs as a return value. There is no such thing withCAutoPtr.auto_ptris deprecated in C++0x. Useunique_ptrif you have to: you can use them in move-aware containers and also get some safety from unsafe implicit moves of l-values.