2020-01-06 19:07:30 +01:00
|
|
|
#include <iostream>
|
|
|
|
#include "Employee.hh"
|
|
|
|
#include "Manager.hh"
|
|
|
|
|
|
|
|
void populate_directory( set<Employee*>& directory ) {
|
|
|
|
// Ownership of caller
|
|
|
|
Employee* wouter = new Employee( "Wouter" , 2);
|
|
|
|
Employee* ivo = new Employee( "Ivo", 3);
|
|
|
|
Manager* stan = new Manager("Stan", 4);
|
|
|
|
Manager* jo = new Manager("Jo", 5);
|
|
|
|
Manager* frank = new Manager("Frank", 6);
|
|
|
|
|
2020-07-09 17:07:15 +02:00
|
|
|
stan->addSubordinate( *wouter );
|
|
|
|
stan->addSubordinate( *ivo );
|
2020-01-06 19:07:30 +01:00
|
|
|
|
|
|
|
directory.insert( stan );
|
|
|
|
directory.insert( wouter );
|
|
|
|
|
|
|
|
// This does not give a problem because stan is also of type Employee
|
2020-07-09 17:07:15 +02:00
|
|
|
frank->addSubordinate( *stan );
|
|
|
|
frank->addSubordinate( *jo );
|
2020-01-06 19:07:30 +01:00
|
|
|
|
|
|
|
directory.insert( wouter );
|
|
|
|
directory.insert( ivo );
|
|
|
|
directory.insert( stan );
|
|
|
|
directory.insert( jo );
|
|
|
|
directory.insert( frank );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Without the virtual keyword in front of Employee:businessCard(),
|
|
|
|
* this function only gives the Employee type of businessCard(), instead of the Manager's variant if applicable
|
|
|
|
*/
|
|
|
|
void printAllCards( const set<Employee*>::iterator begin, const set<Employee*>::iterator end) {
|
|
|
|
for ( auto it = begin ; it != end ; ++it ) {
|
|
|
|
(*it)->businessCard();
|
|
|
|
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
set<Employee*> directory;
|
|
|
|
populate_directory( directory );
|
|
|
|
|
|
|
|
printAllCards( directory.begin(), directory.end() );
|
|
|
|
|
|
|
|
// Delete the contents of the directory
|
|
|
|
for ( auto it = directory.begin() ; it != directory.end() ; ++it ) {
|
|
|
|
delete (*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|