I have an employee class and a server class and am trying to figure out why the printing of the server data in the main function isn't taking the server print() function and using it.
Employee.h:
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <iostream>
using namespace std;
class Employee
{
public:
virtual void job();
void print();
};
#endif
Employee.cpp:
#include "Employee.h"
void Employee::job() {
cout << "Employee status yet to be determined.\n" << endl;
}
void Employee::print() {
cout << "New employee\n" << endl;
}
Server.h:
#ifndef SERVER_H
#define SERVER_H
#include "Employee.h";
#include <iostream>
using namespace std;
class Server : public Employee
{
public:
void job();
void print();
};
#endif
Server.cpp:
#include "Server.h"
void Server::job() {
cout << "Serve tables\n";
print();
}
void Server::print() {
"I am a server!\n";
}
main:
#include "Employee.h"
#include "Server.h"
#include <iostream>
void output(Employee* employee) {
employee->job();
}
int main()
{
Employee* a = new Server;
Employee* b = new Employee;
output(a);
a->print();
output(b);
b->print();
return 0;
}
Just trying to wrap my head around using virtual functions and polymorphism.