inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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