Skip to content

Instantly share code, notes, and snippets.

@xiaom
Last active Dec 18, 2015
Embed
What would you like to do?
inheritance
#include <iostream>
using namespace std;
class Base{
public:
virtual ~Base() {
cout << "Base Destruct" << endl;
}
virtual void print(){
cout << "Base" << endl;
}
};
class Derived: public Base{
public:
virtual ~Derived() {
cout << "Derived destruct" << endl;
}
virtual void print(){
cout << "Derived" << endl;
}
};
int main()
{
Base* pTest1=new Base;
Base* pTest2=new Derived;
pTest1->print();
pTest2->print();
delete pTest1;
delete pTest2;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment