Solved

Why virtual desctructor?

Posted on 2013-06-11
2
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

632 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