Issue
The cyclic dependency is a problem which occurs if two classes includes each other in their header.
#pragma once
#include "egg.hpp"
class Hen {
Egg egg;
};
#include "hen.hpp" // ...
#pragma once
#include "hen.hpp"
class Egg {
Hen hen;
};
#include "egg.hpp" // ...
hen.hpp <---> egg.hpp ↑ ↑ | | | | hen.cpp egg.cpp
Solution
You can fix it if you just declare the other class in the header and include them later in the source file.
#pragma once
class Egg;
class Hen {
Egg egg;
};
#include "hen.hpp" #include "egg.hpp" // ...
#pragma once
class Hen;
class Egg {
Hen hen;
};
#include "egg.hpp" #include "hen.hpp" // ...
hen.hpp egg.hpp ↑ ↖ ↗ ↑ | ⤬ | | / \ | hen.cpp egg.cpp