// File:   03Employee.cpp for CS319-Week 11
// What:   Another example of a static member variable
// Adapted from Deitel, C++ How to Programme, Eg, 7.17

#include <iostream>
#include <string>      

class Employee {
public:
  Employee(const std::string, const std::string); // constructor
  ~Employee(void); // destructor
  const std::string getGivenName() const {return (GivenName);};
  const std::string getFamilyName() const {return (FamilyName);};
  static int getCount() {return(count);};
   
private:
  std::string GivenName;
  std::string FamilyName;
  static int count;  // number of objects instantiated
}; 

// Define and initialize static data member
int Employee::count = 0;

// The constructor sets values of (string) GivenName
// and (string) FamilyName, and it increments the counter
Employee::Employee(const std::string given, const std::string family){
  GivenName = given;
  FamilyName = family;
  count++;  // increment static count of employees
} 

// denstructor decrements the count variable
Employee::~Employee(void){
  count--;  // decrement static count of employees
} 

int main(void)
{
  std::cout << "Number of employees before instantiation is "
	    << Employee::getCount() << std::endl;   // use class name
   
  Employee Driver("Bob", "Wood");
  std::cout << "Now the number of employees is " << 
    Employee::getCount() << std::endl; 
   
  { // New Block. Tom will be local to this block.
    Employee Cleaner("Tom", "Broom");
      
    std::cout << "Employee 1: " << Driver.getGivenName() << " "
	      << Driver.getFamilyName() << std::endl;
      
    std::cout << "Employee 2: " << Cleaner.getGivenName() << " "
	      << Cleaner.getFamilyName() << std::endl;
      
    std::cout << "Cleaner.getCount() returns " << 
      Cleaner.getCount() << std::endl;
    // Calling Cleaner.getCount() same as calling Driver.getCount() 
    // and the same as calling Employee::getCount().

    std::cout << "Exiting Tom's block." << std::endl;
  }
  std::cout << "There is " << Employee::getCount() << 
    " worker left." << std::endl;
  return (0);
}

