Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Why virtual desctructor?

Posted on 2013-06-11
2
Medium Priority
?
338 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 1600 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

971 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