#include
#include
#include
#include
#include
#include
#include
using namespace std;
class Base
{
public:
Base() {cout << "Base con" << endl;}
virtual ~Base()
{
cout << "Base destructor" << endl;
}
virtual void Hiberarchy() const = 0;
};
void Base::Hiberarchy() const//pure virtual also can have function body
{
cout << "Base::Hiberarchy" << endl;
}
class Derived : public Base
{
public:
Derived() {cout << "Derived con" << endl;}
virtual void Hiberarchy() const
{
Base::Hiberarchy();
cout << "Derived::Hiberarchy" << endl;
}
// virtual ~Derived()
~Derived()
{
cout << "Derived destructor" << endl;
}
virtual void foo(){cout << "Derived foo()" << endl;}
};
int main()
{
Base *pb = new Derived();
pb->Hiberarchy();
pb->Base::Hiberarchy();
delete pb;
Derived derivedObj;
derivedObj.foo();
//cout << << endl;
return 0;
}