Derived Classes Don't "need"type of generic "employee" Since no one's just an "employee" General concept of employee helpful! ◆All have names All have social security numbers Associated functions for these "basics"are same among all employees So "general"class can contain all these "things"about employees Copyright 2006 Pearson Addison-Wesley.All rights reserved. 14-6
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-6 Derived Classes ¨ Don’t "need" type of generic "employee" ¨ Since no one’s just an "employee" ¨ General concept of employee helpful! ¨ All have names ¨ All have social security numbers ¨ Associated functions for these "basics" are same among all employees ¨ So "general" class can contain all these "things" about employees
Employee Class Many members of "employee"class apply to all types of employees ◆Accessor functions ◆Mutator functions ◆Most data items: ◆SSN ◆Name ◆Pay We won't have "objects"of this class,however Copyright006 Pearson Addison-Wesley.All rights reserved. 147
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-7 Employee Class ¨ Many members of "employee" class apply to all types of employees ¨ Accessor functions ¨ Mutator functions ¨ Most data items: ¨ SSN ¨ Name ¨ Pay ¨ We won’t have "objects" of this class, however
Employee Class Consider printCheck(function: Will always be "redefined"in derived classes So different employee types can have different checks Makes no sense really for "undifferentiated" employee So function printCheck(in Employee class says just that Error message stating "printCheck called for undifferentiated employee!!Aborting." Copyright 2006 Pearson Addison-Wesley.All rights reserved. 14-8
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-8 Employee Class ¨ Consider printCheck() function: ¨ Will always be "redefined" in derived classes ¨ So different employee types can have different checks ¨ Makes no sense really for "undifferentiated" employee ¨ So function printCheck() in Employee class says just that ¨ Error message stating "printCheck called for undifferentiated employee!! Aborting
Deriving from Employee Class Derived classes from Employee class: Automatically have all member variables Automatically have all member functions Derived class said to "inherit"members from base class Can then redefine existing members and/or add new members Copyright006 Pearson Addison-Wesley.All rights reserved. 14-9
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-9 Deriving from Employee Class ¨ Derived classes from Employee class: ¨Automatically have all member variables ¨Automatically have all member functions ¨ Derived class said to "inherit" members from base class ¨ Can then redefine existing members and/or add new members
Display 14.3 Interface for the Derived Class HourlyEmployee (1 of 2) Display 14.3 Interface for the Derived Class HourlyEmployee 2 //This is the header file hourlyemployee.h. 3 //This is the interface for the class HourlyEmployee. 4 #ifndef HOURLYEMPLOYEE_H 5 #define HOURLYEMPLOYEE_H 6 #include <string> 7 #include "employee.h" 8 using std:string; 9 namespace SavitchEmployees 10{ Copyright 2006 Pearson Addison-Wesley.All rights reserved. 14-10
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-10 Display 14.3 Interface for the Derived Class HourlyEmployee (1 of 2)