#include using namespace std ; //Abstract Class class Person { public: string firstName ; string lastName ; //virtual virtual void getName() = 0 ; /* { cout << firstName << " " << lastName << endl ; } */ Person() { cout << "Person Constructor." << endl ; } virtual ~Person() { cout << "Person Destructor." << endl ; } }; class Employee : public Person { public: string jobTitle ; //if no implementation for getName //then this class is also abstract /* virtual void getName() { cout << firstName << " " << lastName << " " << jobTitle << endl ; } */ Employee() { cout << "Employee Constructor." << endl ; } virtual ~Employee() { cout << "Employee Destructor." << endl ; } }; //This is not an abstract class class Manager : public Employee { public: //What if the method is missing //Climb up the hierarchy virtual void getName() { cout << firstName << " " << lastName << " " << jobTitle << " Manager" << endl ; } Manager() { cout << "Manager Constructor." << endl ; } virtual ~Manager() { cout << "Manager Destructor." << endl ; } }; int main() { Person* p1 ; Employee* e1 ; Manager* m1 ; // Compiler error // p1 = new Person() ; //Not Allowed //e1 = new Employee() ; //delete e1 ; //Allowed m1 = new Manager() ; delete m1 ; /* e1 = new Employee() ; e1->firstName = "Chuck" ; e1->lastName = "Wepner" ; e1->jobTitle = "Boxer" ; p1 = e1 ; //p1->getName() ; delete e1 ; cout << endl << endl ; m1 = new Manager() ; m1->firstName = "Chuck" ; m1->lastName = "Wepner" ; m1->jobTitle = "Boxer" ; p1 = m1 ; //e1->getName() ; //Make sure we delete the right type //or program will crash delete m1 ; */ return 0 ; }