Can you give an example of how your headers look instead of just which includes the other?
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
If you want your classes to use each other, you pretty much need to do something like this using forward declarations and pointers (preferably smart pointers as they make your life easier):
#ifndef FLOOR_H
#define FLOOR_H
#include <memory>
class Control;
class Floor
{
public:
Floor(void);
~Floor(void);
private:
std::auto_ptr<Control> control;//to send requests
};
#endif
#ifndef CONTROL_H
#define CONTROL_H
#include <memory>
class Floor;
class Lift;
class Control
{
public:
Control();
~Control(void);
private:
std::auto_ptr<Floor> floor;//to update floor display
std::auto_ptr<Lift> lift;//to tell lift what to do
};
#endif
#ifndef LIFT_H
#define LIFT_H
#include <memory>
class Control;
class Lift
{
public:
Lift();
~Lift(void);
private:
std::auto_ptr<Control> control;//to send requests
};
#endif
If you don't want to do that, you would be better off restructuring the classes so that they don't depend on each other:
class Floor
{
public:
Floor();
~Floor();
};
class Lift
{
public:
Lift();
~Lift();
private:
Floor floor[20]; // 20 story building
};
class Control
{
public:
Control();
~Control();
private:
Lift lift;
};
Control manipulates Lift through the Lift public interface and Lift manipulates the array of Floor through the Floor public interface. Any messaging is done that way. Of course, I don't know how your design is set up, so this suggestion may not work without significant changes.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401