I'm writing a program to schedule nurses in a hospital. I'm stuck with an inclusion loop between two classes, but I don't know where I made an error. There's a nurse class that has an instance of a Preference Profile. This preference profile has a pointer to the Nurse object.
Header of the Nurse class:
//Include guards
#ifndef NURSEDEF
#define NURSEDEF
#pragma once
//Forward declared dependencies
class Department;
//Included dependencies
#include "PrefProfile.h"
//Actual class
class Nurse
{
public:
Nurse();
~Nurse();
Nurse(string id, Department *dept);
Nurse(int type, double emplRate, Department *dept);
Department* getDept();
string getID();
bool setType(int type);
void setEmplRate(double emplRate);
bool setPrefProfile(int day, int shift, int value);
private:
string ID;
double emplRate;
int type;
Department *dept;
PrefProfile pref;
};
#endif
Header of the PrefProfile class:
//Include guards
#ifndef PREFPROFILEDEF
#define PREFPROFILEDEF
#pragma once
//Forward declared dependencies
class Nurse;
//Included dependencies
#include "Support.h"
//Actual class
class PrefProfile
{
public:
PrefProfile();
~PrefProfile();
PrefProfile(Nurse *nurse);
bool addPref(int day, int shift, int pref);
int readPref(int day, int shift);
private:
Nurse *nurse;
int profile[maxDays][maxShifts];
};
#endif
As PrefProfile only contains a pointer to a nurse object I forward declared it instead of including the header file. The Nurse class includes the header of PrefProfile. I encounter the following error at the object pref in the Nurse class: C3646 'pref':unknown override specifier.
I'm pretty new to C++ and I read that this approach to reference should be used. Is there an easy way to avoid this kind of inclusion loops? Or am I missing something in my code?