56 lines
1.4 KiB
C++
56 lines
1.4 KiB
C++
#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);
|
|
|
|
(*stan).addSubordinate( *wouter );
|
|
(*stan).addSubordinate( *ivo );
|
|
|
|
directory.insert( stan );
|
|
directory.insert( wouter );
|
|
|
|
// This does not give a problem because stan is also of type Employee
|
|
(*frank).addSubordinate( *stan );
|
|
(*frank).addSubordinate( *jo );
|
|
|
|
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;
|
|
}
|