我的代码中有以下头文件。我知道问题是循环依赖正在发生,但我似乎无法解决它。 任何帮助解决它?循环依赖C++
project.h让我这个错误:字段 '位置' 具有不完全类型
#ifndef PROJECT_H_
#define PROJECT_H_
#include <string.h>
#include "department.h"
class department;
class project{
string name;
department location;
public:
//constructors
//Setters
//Getters
};
#endif
employee.h让我这个错误域 “”myDepartment具有不完整的类型“
#ifndef EMPLOYEE_H_
#define EMPLOYEE_H_
#include "department.h"
#include <vector>
class department;
class project;
class employee
{
//attributes
department myDepartment;
vector <project> myProjects;
public:
//constructor
// Distructor
//Setters
//Getters
#endif
部门.h
#ifndef DEPARTMENT_H_
#define DEPARTMENT_H_
#include <string.h>
#include "employee.h"
#include "project.h"
#include <vector>
class project;
class employee;
class department{
private:
string name;
string ID;
employee headOfDepatment;
vector <project> myprojects;
public:
//constructors
//Setters
//Getters
};
#endif
删除.h文件中的所有循环包含:“employee.h”,“project.h”和“department.h” – Mercurial
您正在使用正向声明的正确轨道上,但您只需要对文件。 – Damian