Thread: Virtual & Pure virtual destructors

  1. #61
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    It took me a few books to locate it, the best description that I could find by quickly searching was in Effective C++ Second Edition by Scott Meyers.

    I think though, that if you just design your abstract class appropriately than a pure virtual destructor is not necessary. BTW I also read that all inheritance hierarchies should use an abstract base class.

  2. #62
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001

    I don't think you should look at it that way. It's simply that if you are writing an abstract base class, you will need a pure virtual function in the class (obviously). This means that you will have to have at least one function in the class that _must_ be overridden by any derived class. There may be instances where a common function needs to be defined in the base class or where there is no common function that you want all derived classes to have to define (I have come across this before) and since you can't simply stick a do-nothing function in as a pure virtual, you will see that there is no choice but to make the destructor pure virtual. Keep in mind, as well, that you can still give the destructor a body even though it's pure virtual.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-28-2009, 09:25 AM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. Information Regarding Pure Virtual Functions
    By shiv_tech_quest in forum C++ Programming
    Replies: 6
    Last Post: 01-29-2003, 04:43 AM
  4. C++ XML Class
    By edwardtisdale in forum C++ Programming
    Replies: 0
    Last Post: 12-10-2001, 11:14 PM
  5. virtual or pure virtual
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-01-2001, 07:19 PM