.net - virtual destructor -


Can someone explain the concept of virtual destructor to me? And how is it taken care of in DotNet?

The following programs show the need for a virtual constructor,

  #include & Lt; Iostream & gt; # Include & lt; Conio.h & gt; using namespace std; Square base {public: base () {cout & lt; & Lt; "Constructor: Base" & lt; & Lt; Endl;} ~ base () {cout & lt; & Lt; "Destruction: Base" & lt; & Lt; Endl;}}; Categories made: Public base {Public: Derivative () (cout & lt; "constructor: derivative" & lt; endl;} ~ Dated () {cout << ct & lt; & lt; "Distribution: Derivatives " 

You see in the above program:

Destructors of the base class are not virtual and therefore the above program will be produced as follows,

  Constructor: Base Constructor TER: Derived Destructor: Base  

In the above case, the derivative object is not called the destroyer. Therefore, if you create the baster class destructor as a virtual, the output will be as follows:

  Constructor: Base constructor: Detector Detector: Detector Distinctor: Base  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -