virtual destructor
-
Hi can anybody give me a sample code regarding what we have to write in a virtual destructor of base & derived class. What we have to write to call the destructor.? bye
-
Hi can anybody give me a sample code regarding what we have to write in a virtual destructor of base & derived class. What we have to write to call the destructor.? bye
lavate malllik wrote:
can anybody give me a sample code regarding what we have to write in a virtual destructor of base & derived class.
try http://www.parashift.com[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY-
-
Hi can anybody give me a sample code regarding what we have to write in a virtual destructor of base & derived class. What we have to write to call the destructor.? bye
you write a destructor to deallocate te memory allocated dynamically during the object's life (from construction to now - destruction). the fact a destructor is virtual or not is a matter of inheritence and doesn't affect what you write in the destructor body. and to call the destructor, you don't have to do anything much. an object is automattically when the execution goes out of the scope of the object.
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
Hi can anybody give me a sample code regarding what we have to write in a virtual destructor of base & derived class. What we have to write to call the destructor.? bye
Seehttp://new-brunswick.net/workshop/c++/faq/virtual-functions.html[^] if its good for you
_**
**_
WhiteSky
-
lavate malllik wrote:
can anybody give me a sample code regarding what we have to write in a virtual destructor of base & derived class.
try http://www.parashift.com[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY-
thanks for reply.. can u give me a piece of code where it shows it has written something in destructor...? i wnat to knwo what we have to write in a destructor of base & derived class when base class destructor is virtual? are we have to write any thing is any one of destructor?
-
you write a destructor to deallocate te memory allocated dynamically during the object's life (from construction to now - destruction). the fact a destructor is virtual or not is a matter of inheritence and doesn't affect what you write in the destructor body. and to call the destructor, you don't have to do anything much. an object is automattically when the execution goes out of the scope of the object.
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
SAY if my destructor body is empty & I call delete p.it will call destructor & ultimately it will destroy the object of base & derived irrespective of empty body of destructor....
-
SAY if my destructor body is empty & I call delete p.it will call destructor & ultimately it will destroy the object of base & derived irrespective of empty body of destructor....
Here is a very simple illustration on how they work:
class Base { public: Base() { cout << "Base::Base()" << endl; } virtual ~Base() { cout << "Base::~Base()" << endl; } }; class Derived : public Base { public: Derived() { cout << "Derived::Derived()" << endl; } virtual ~Derived() { cout << "Derived::~Derived()" << endl; } }; void main() { Base b; Derived d; }
Output: Base::Base() Base::Base() Derived::Derived() Derived::~Derived() Base::~Base() Base::~Base()
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac