0

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

    employee headOfDepartment;

这些 setter 和 getter 有什么问题?

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

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

我一直在尝试用组合定义 setter 和 getter,但它一直给我这个错误:“字段 'headOfDepartment' 的类型不完整”

好的这些是头文件:

   #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

部门.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

项目.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
4

3 回答 3

1

您需要包含在头文件employee和源文件中声明的头文件department

于 2013-11-06T19:19:20.880 回答
1

在使用它作为对象的类型名称之前,应定义类雇员。我还建议为 getter 添加限定符 const

于 2013-11-06T19:20:08.860 回答
0

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

于 2013-11-06T19:19:17.517 回答