I’d like to know do I need to write destructor in classes when I don’t use raw pointers anymore? Just boost smart pointers.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Boost smart pointers by themselves don’t have anything to do with the need for a destructor. All they do is remove the need for you to call delete on the allocated memory that they are effectively managing. So having said that, if before you started using smart pointers all you had in your destructors were calls to delete and delete[] freeing the memory of dynamically allocated class members and you have now switched all those regular pointers over to smart pointers, you could probably just switch to an empty destructor as they will now clean up for themselves when they go out of scope.
However, if for whatever reason, you have a class that needs to do cleanup (file cleanup, sockets, other resources etc) you will still need to provide a destructor to do that.
Let me know if that helps.