I've got these 3 questions, I didn't work so far in C++, and this is preparation for my C++ class, These questions are a little tricky and unknown to me, I tried to find the answers in Wikipedia, but I didn't manage, if anyone can answer me, please.

1.1 Can a destructor, defined in a base class, be inherited by a derived class?

1.2 Can a base class destructor be overridden in a derived class?

1.3 Does an abstract class need a contructor?


Thank you very much, I would appreciate all help, and if someone has links with examples where I can see how it works.

Recommended Answers

All 2 Replies

1.1 Can a destructor, defined in a base class, be inherited by a derived class?

1.2 Can a base class destructor be overridden in a derived class?

1.3 Does an abstract class need a contsructor?

You're clearly realising that the Constructors and Destructors are not your average method. Good stuff.
1.1 Can a destructor, defined in a base class, be inherited by a derived class?
Destructors and constructors don't behave as other methods. Even if a base class destructor is not virtual, it will still be called when the derived class is destroyed because the base will also be destroyed immediately afterwards.
A normal inherited method would just call the derived class implementation of course.

1.2 Can a base class destructor be overridden in a derived class?
Yes it can be overridden, and it usually should be. If you have a pointer to the base class and destroy it, it is important that the destructor of the derived class is called to clean it up. That in turn will call the base class destructor.

1.3 Does an abstract class need a contsructor?
No it doesn't. Abstract base classes don't usually contain member data. Though, they can do, and if so they may need a constructor.

Thank you on your answer. I will mark it as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.