Question

when I have the following member in a class

    employee headOfDepartment;

what's wrong these setters and getters?

void department::setHeadOfDepartment( employee depEmployee)
    {
        headOfDepartment=depEmployee;
    }

employee department::getHeadOfDepartment() 
{
    return headOfDepartment;
}

I've been trying forever to define setters & getters with composition and it keeps getting me this error: "field ‘headOfDepartment’ has incomplete type"

ok Those are the header files:

   #ifndef EMPLOYEE_H_
#define EMPLOYEE_H_
using namespace std;
#include <iostream>
#include <vector>
#include "department.h"
#include "project.h"
class department;
class project;

//#include <vector>

employee.h 

class employee
{
string Name; //text with spaces
string National_ID; //unique value (text) for each employee
static double Salary; // value of 1500 pounds
char Gender; //character holds f or m
int Available_vacations; //initially starts with 15 days
static double Deduction_per_day; // value of 85.5 pounds
int Available_permission_hours; //initially starts with 20 hours
static double Deduction_per_hour; // value of 15.5 pounds
double Actual_salary; // value with actual salary after deductions
int Vacations; // vacations employee took
int Permessions; // permession hours employee took
int empSerialNum; // object order in vector
department* myDepartment;
vector < project > empProjects;

public:
employee (); // default constructor
employee (string myName, string myNationalID, char myGender,int mySerialNum); // Parameterized constructor
~employee(); // Destractor

    //Setters
    void setName(string myName);
    void setNationalID (string myNationalID);
    void setGender (char myGander);
    void setAvailableVacation(int myAvVac);
    void setAvailablepermissionhours (int myAvPerHours);
    void setActualSalary (double actualSalary);
    void setVacations(int myVacations);
    void setPermessions(int myPermessions);
    void setempSerialNum(int mySerialNum);
    void setDepartment(department*);
    void addProject(project);

    //Getters
    string getName();
    string getNationalID ();
    char getGender ();
    int getAvailableVacation();
    int getAvailablepermissionhours ();
    double getActualSalary ();
    int getVacations ();
    int getPermessions ();
    int getempSerialNum();
    department* getDepartment();
    project* getProjects();



    void view (); // View to view Name, ID and actual salary

    void View_Detailed (); //call previous function and also shows other details (vacations - permissions - detailed deductions - ... )

    void Free_All(); //return all values to default

    double Take_vacation(); //this function takes number of days employee need to take as vacation, available vacations reduced by number of days given, if available vacations became 0 salary is deduced by deduction per day set

    double Take_permession(); //this function takes hours that employee asked to take, reduce available permission hour by hours given, if available permission become 0 hour salary is reduced by deduction per ho

    double Calculate_Actual_Salary();// calculates salary after deductions and returns it
};

#endif

department.h

#ifndef DEPARTMENT_H_
#define DEPARTMENT_H_
using namespace std;
#include <string.h>
#include "employee.h"
#include "project.h"
#include <vector>


class project;
class employee;

class department{

private:
    string name;
    string ID;
    employee headOfDepartment;


    vector <project> depprojects;  //projects managed by the department
public:

    //constructors
    department();
    department(string, string);


    //Setters
    void setName(string);
    void setID(string);
    void setHeadOfDepartment( employee /*const&*/ depEmployee);
    void addProject(project);

    //Getters
    string getName();
    string getID();
    employee getHeadOfDepartment() /*const*/;
//  project getProjects();

};

#endif

project.h

#ifndef PROJECT_H_
#define PROJECT_H_
#include <string.h>
#include "department.h"
#include "project.h"

class department;

class project{

    string name;
    department* location;

public:
    //constructors
    project();
    project(string proName, department* proDepartment);

    //Setters
    void setName(string proName);
    void setLocation(department* proDepartment);

    //Getters
    string getName();
    department* getLocation();

};


#endif
Was it helpful?

Solution

You need to the include the header file where employee is declared in your header and source files for department

OTHER TIPS

Class employee shall be defined before using it as a type name of an object. Also I advice to add qualifier const for the getter

You are not including the header that defines employee in your department class header, but you have a non-reference non-pointer declaration of type employee in your header.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top