编译错误:变量类型不完整

时间:2019-07-10 21:22:16

标签: c++ compiler-errors

这是制造错误:

In file included from /Users/ingmar/src/maxr/src/game/data/map/map.cpp:32:
/Users/ingmar/src/maxr/src/game/data/model.h:221:22: error: variable has incomplete type
      'cPlayerBasicData'
                                cPlayerBasicData basicPlayerData;
                                                 ^
/Users/ingmar/src/maxr/src/game/data/player/player.h:48:7: note: forward declaration of
      'cPlayerBasicData'
class cPlayerBasicData;
      ^

我将尝试包含相关代码。

model.h:

...
#include "game/data/player/player.h"
...
class cPlayerBasicData;
...
class cModel
{
    ...
    template<typename T>
    void load(T& archive)
    {
        ...
        for (auto& player : playerList)
        {
            if (player == nullptr)
            {
                cPlayerBasicData basicPlayerData; // <- this is line 221
                player = std::make_shared<cPlayer>(basicPlayerData, *unitsData);
            }

player.h:

...
class cPlayerBasicData; // <- this is line 48
...
class cPlayer
{
    ...

player.h包含在model.h中,因此cPlayerBasicData有效地向前声明了两次。这是错误的原因吗?

0 个答案:

没有答案