Base class should have virtual destructor if up-casting takes place and we try to delete child object through base class pointer. In this situation, base class does not need to have any other virtual methods apart from destructor!
If ~A() wasn’t virtual, delete pA would have invoked only ~A() which would cause memory leak.
If ~A() wasn’t virtual, delete pA would have invoked only ~A() which would cause memory leak.
No comments:
Post a Comment