To start, let's discuss RAII & Smart Pointer .
I always thought Smart Pointer as shared_ptra good RAII practice, because it gets the heap memory resource in the constructor, for example
shared_ptr<A> pA(new pA());
and can free memory at the right time through reference counting and its destructor.
However, this morning my colleague told me that:
smart pointer is not what I considered RAII . The only thing that can be strictly called RAII in STL is the std::lock_guardrest - no more than RRID . "
Am I also misunderstood something? Or what my colleague said doesn't actually make sense?
source
share