Virtual & Pure virtual destructors

This is a discussion on Virtual & Pure virtual destructors within the C++ Programming forums, part of the General Programming Boards category; It took me a few books to locate it, the best description that I could find by quickly searching was ...

  1. #61
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    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
    Posts
    856
    BMJ,

    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.

Page 5 of 5 FirstFirst 12345
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, 03:43 AM
  4. C++ XML Class
    By edwardtisdale in forum C++ Programming
    Replies: 0
    Last Post: 12-10-2001, 10:14 PM
  5. virtual or pure virtual
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-01-2001, 06:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21