Solved

Why virtual desctructor?

Posted on 2013-06-11
2
318 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
 
LVL 1

Author Closing Comment

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

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Fully specialized class template function 21 136
How to split this in C++ 4 102
White board coding practice 3 88
passing data from one form to another form in c++ 27 80
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

770 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