Solved

Why virtual desctructor?

Posted on 2013-06-11
2
314 Views
Last Modified: 2013-06-11
class Socket   // This is an Interface class and must be overriden to work.
{
  public:  
    enum SocketErrorValue
    {
      SocketErrorValue_None             = 0,
      SocketErrorValue_SocketNotOpen    = -1,
      SocketErrorValue_ConnectionClosed = -2,
      SocketErrorValue_WriteBufferFull  = -3,
      SocketErrorValue_InvalidParameter = -4,
      SocketErrorValue_Timeout          = -5,
      SocketErrorValue_NoData           = -6,
      SocketErrorValue_InListenMode     = -7
    };


    /// <summary>Descructor
    /// </summary>
    virtual ~Socket() {};
    ...
    ...


In above base class, is destrctor 'virtual' so it can be overridden by a class that inherits this base class?
0
Comment
Question by:naseeam
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 400 total points
ID: 39238365
The reason for the destructor being virtual is to ensure that the base class' destructors are calledm and that will happen in the right order. See http://www.codersource.net/c/c-miscellaneous/c-virtual-destructors.aspx ("C++ Virtual destructors") and http://blogs.msdn.com/b/oldnewthing/archive/2004/05/07/127826.aspx ("When should your destructor be virtual?")
0
 

Author Closing Comment

by:naseeam
ID: 39238501
Great articles that anwer the exact question asked.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now