Virtual destructor example added.

This commit is contained in:
Kolan Sh 2014-03-09 14:47:56 +04:00
parent 25eb3c82dc
commit 046d0da873
1 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,31 @@
#include <iostream>
using namespace std;
class A1 {
public:
A1 () {
cout << "A1() called" << endl;
}
virtual ~A1 () { // won't be called if non-virtual
cout << "~A1() called" << endl;
}
};
class A2 : public A1 {
public:
A2 () {
cout << "A2() called" << endl;
}
~A2 () {
cout << "~A2() called" << endl;
}
};
int main (int argc, char *argv[])
{
A1 *ap = new A2();
delete ap;
}