To start with, here is a discussion of RAII&Smart Pointer.
I've always thought that Smart Pointer like shared_ptr
is a good practice of RAII because it gets the heap memory resource at constructor like
shared_ptr<A> pA(new pA());
and could free the memory at right time through reference counting and its destructor.
However, this morning my collegue told me that:
"smart pointer is not what i thought to be RAII. The only thing that can strictly be called as RAII in the STL is
std::lock_guard
, the others are nothing more than RRID. "
So did i get something wrong? Or what my collegue said actually made non-sense?