How do I define two C++ classes with pointers to each other?
I'm trying to make two classes that hold a pointer or variable of the other, like this (pseudo-code):
---unit.h---
Code:
#ifndef UNIT_H
#define UNIT_H
#include "action.h"
#include <vector>
using namespace std;
class Unit {
vector<Action> actions;
int hp;
};
#endif
---action.h---
Code:
#ifndef ACTION_H
#define ACTION_H
#include "unit.h"
class Action {
Unit *target_unit;
int action_type;
};
#endif
But since one is defined inside the other, it can't compile the program. It reads in action.h and sees unit.h is included, when it read unit.h, it says Action is not defined. Is there a way around error?