这有什么问题?包括Setters / Getters(已编辑)头文件

时间:2013-11-06 19:16:39

标签: c++ setter composition getter

当我在班级中有以下成员时

    employee headOfDepartment;

这些安装者和吸气者有什么不对?

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

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

我一直在努力定义setter&具有组合的getter并且它一直让我犯这个错误:"字段'headOfDepartment'的类型不完整"

ok这些是头文件:

   #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

3 个答案:

答案 0 :(得分:1)

您需要在employee

的标题和源文件中包含声明department的头文件

答案 1 :(得分:1)

在将员工用作对象的类型名称之前,应定义该员工。另外我建议为getter添加限定符const

答案 2 :(得分:0)

您没有在部门类标题中包含定义员工的标题,但您的标题中有一个类型为employee的非引用非指针声明。