0

Say I have an object A who'se destructor I need to override for some reason

class A 
{ 
private: 
    shared_ptr<B> m_ptr; 
public: 
    A(shared_ptr<B> ptr) {m_ptr = ptr}
    ~A() {m_ptr.reset() // is this needed?
}

Do I need to reset the shared_ptr it holds because if I was using the default destructor, it would have called the shared_ptr's destructor inside of it?

rstr1112
  • 308
  • 4
  • 13
  • [RAII is your friend.](https://stackoverflow.com/questions/2321511/what-is-meant-by-resource-acquisition-is-initialization-raii) – user4581301 Jul 24 '20 at 21:01

1 Answers1

2

No.

The pointer cleanup is provided by the destructor of the shared pointer, which is called automatically.

See the relevant entry in isocpp faq: When I write a destructor, do I need to explicitly call the destructors for my member objects?

Paul92
  • 8,827
  • 1
  • 23
  • 37