Name: Ben
Status: N/A
Age: N/A
Location: N/A
Country: N/A
Date: Around 1995
Question:
Is there a way to override the base class destructor's execution in the
derived class' destructor in case the derived class needs to handle a
member's deletion differently?
Replies:
Ok, here is something that you can try:
In the base class, make the destructor virtual. For example, instead of:
~base_class(); do this: virtual ~base_class();
Now, within the derived class, you should be able to do this:
~base_class();
If you do not "overload" ~base_class() within the derived class, then the
original destructor will be invoked when an instance of the class goes out
of scope. Otherwise, the code that you have within the derived class will
be used for ~base_class() when an instance goes out of scope.
Understand all of that?
NEWTON is an electronic community for Science, Math, and Computer Science K-12 Educators, sponsored and operated by Argonne National Laboratory's Educational Programs, Andrew Skipor, Ph.D., Head of Educational Programs.