Код: Выделить всё
Game.hpp
Код: Выделить всё
#ifndef GAME_HPP
#define GAME_HPP
#include
class Phase; // Forward declaration
class Game
{
private:
static inline Game* instance_reference_{nullptr};
std::unique_ptr
current_phase_;
bool is_running_{true};
explicit Game() {};
public:
virtual ~Game();
const static Game* getInstance();
Код: Выделить всё
Story.hpp
Код: Выделить всё
#ifndef PHASE_HPP
#define PHASE_HPP
class Game; // Forward declaration
class Phase
{
protected:
const Game* game_;
public:
explicit Phase() : game_{ Game::getInstance() } {};
virtual ~Phase() = default;
virtual void handlePhase() = 0;
};
#endif
Сейчас я не могу скомпилировать, поскольку Game::getInstance() нигде не объявлен.
но когда я переключаюсь на #include "Game.hpp"вместо предварительного объявления, при компиляции я получаю эту ошибку:
Код: Выделить всё
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/unique_ptr.h:97:16: error: invalid application of 'sizeof' to an incomplete type 'Phase'
97 | static_assert(sizeof(_Tp)>0,
| ^~~~~~~~~~~
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/unique_ptr.h:404:4: note: in instantiation of member function 'std::default_delete
::operator()' requested here
404 | get_deleter()(std::move(__ptr));
| ^
./Game.hpp:36:14: note: in instantiation of member function 'std::unique_ptr::~unique_ptr' requested here
36 | explicit Game() {};
| ^
./Game.hpp:13:7: note: forward declaration of 'Phase'
13 | class Phase; // Forward declaration
| ^
Подробнее здесь: https://stackoverflow.com/questions/784 ... leton-in-c