Hi I'm a C++ newbe,
I've created a simply project in Eclipse called Employee, it contains a main
and three classes one called Employee which has two subclasses VolEmp and TempEmp
I'm trying to enable access to both classes in my main, but I'm only able to include one of them without getting complaints, had assumed I should just write
#include "Employee.h"
#include "VolEmp.h"
#include "TempEmp.h" to enable access to all three classes but if i enable more than one of these I keep getting the following errors:
error: redefinition of `class Employee'
error: previous definition of `class Employee'
I include my full main and hope someone could please tell me how to enable access to all tree classes...
/*
* main.cpp
*
* Created on: 08-Nov-2008
* Author: Patrick Nevin: 06754155
*/
#include <iostream>
#include <fstream>
#include <vector>
//#include "Employee.h"
//#include "VolEmp.h"
#include "TempEmp.h"
usingnamespace std;
int main() {
//read in the employee data file
fstream empStream("emp.dat");
//create a vector of Employee objects
vector<Employee> workers;
//used to hold the current word in the stream....
string current;
//as we iterate over each word in it
while (empStream >> current) {
//the current employee's name
string name;
//the current employee's surname
string s_name;
//the current employee's wage
double wage;
//if the current word is TEMP read in info and create a new TempEmp object
if (current == "TEMP") {
empStream >> name;
empStream >> s_name;
empStream >> wage;
Employee *e = new TempEmp(name, s_name, current);
e->set_wage(wage);
//And add it to the vector
workers.push_back(*e);
delete e;
}
//if the current word is TEMP read in info and create a new TempEmp object
if (current == "FULL") {
empStream >> name;
empStream >> s_name;
empStream >> wage;
Employee *em = new Employee(name, s_name, current);
em->set_wage(wage);
//And add it to the vector
workers.push_back(*em);
delete em;
}
//if the current word is VOL read in info and create a new VolEmp object
if (current == "VOL") {
empStream >> name;
empStream >> s_name;
// Should be new VolEmp here but can olny include
//either VolEmp of TempEmp but not both??
Employee *emp = new Employee(name, s_name, current);
emp->set_wage(wage);
//And add it to the vector
workers.push_back(*emp);
delete emp;
}
}//end while()
empStream.close();
vector<Employee>::iterator it;
for (it = workers.begin(); it != workers.end(); it++) {
Employee current = *it;
current.print();
}
return 0;
}