Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #ifndef EMPLOYEE_HH
  2. #define EMPLOYEE_HH
  3.  
  4. #include <set>
  5. #include <string>
  6. #include <iostream>
  7.  
  8. using namespace std ;
  9.  
  10. class Employee {
  11. public:
  12. // Constructor
  13. Employee(const char* name, double salary) :
  14. _name(name),
  15. _salary(salary) {
  16. }
  17.  
  18. // Accessors
  19. const char* name() const {
  20. return _name.c_str() ;
  21. }
  22. double salary() const {
  23. return _salary ;
  24. }
  25.  
  26. private:
  27. string _name ;
  28. double _salary ;
  29.  
  30. } ;
  31.  
  32. class Manager : public Employee {
  33. public:
  34. //Constructor
  35. Manager(const char* _name, double _salary):
  36. Employee(_name, _salary),
  37. _subordinates() {
  38. }
  39.  
  40. // Accessors/Modifiers
  41. void addSubordinate(Employee& empl) {
  42. _subordinates.insert(empl) ; // Error: no macthing function call for .insert()
  43. }
  44.  
  45. private:
  46. set<Employee*> _subordinates ;
  47.  
  48. } ;
  49.  
  50. #endif
  51.  
  52. #include <string>
  53. #include <iostream>
  54. #include "Employee.hh"
  55.  
  56. using namespace std ;
  57.  
  58. int main() {
  59.  
  60. Employee emp = ("David", 10000) ;
  61.  
  62. Manager mgr = ("Oscar", 20000) ;
  63.  
  64. mgr.addSubordinate(emp);
  65.  
  66. return 0;
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement