我的代碼中有以下頭文件。我知道問題是循環依賴正在發生,但我似乎無法解決它。 任何幫助解決它?循環依賴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