Skip to content

Instantly share code, notes, and snippets.

@xiaom
Last active December 18, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiaom/5852439 to your computer and use it in GitHub Desktop.
Save xiaom/5852439 to your computer and use it in GitHub Desktop.
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