Thursday, 5 September 2013

When default destructor is enough for the class?

When default destructor is enough for the class?

Let's say we have three classes: Parent, Child and Other.
class Parent: {
public:
Parent(std::string title): m_title(title) { }
void setTitle (std::string title);
private:
std::string m_title;
};
class Child: public Parent {
public:
Child(std::string title) { setTitle(title); }
private:
Other object;
};
class Other {
public:
Other() : m_body("") { }
std::string body();
void setBody(std::string);
private:
std::string m_body;
};
Is it OK to use default destructors for all of these classes?
My point is, since I'm not allocating any memory manually, I don't need to
care about its deallocation.
The Big Question: Is there a general rule when default destructor is enough?

No comments:

Post a Comment