继续尝试解析类不命名类型

Keep tryning to resolve a class Does not name a Type

本文关键字:类型 继续      更新时间:2023-10-16

我遇到的问题就像标题中说的"Effect" does not name a type,所以我搜索并找到了关于去操作,然后是初始化,所以我在代码中添加了一行class Effect;,给出了关于field has incomplete type的另一个错误,当搜索时,我发现这是由于前向声明,所以现在我不知道该怎么办。。。。我认为问题是我有一个循环包含,以下是文件:

错误代码:

#ifndef RUNE_HPP_INCLUDED
#define RUNE_HPP_INCLUDED
#include "Ressources.hpp"
#include "Effect.hpp"
class Effect; //Declaration of Effect
class Rune{
public:
    Rune();
    target getTarget();
    effect getEffectName();
private:
    Effect eff;  //Error is here , with this code it is incomplete type
};
#endif // RUNE_HPP_INCLUDED

生效时间:

#ifndef EFFECT_HPP_INCLUDED
#define EFFECT_HPP_INCLUDED
#include "Ressources.hpp"
#include "Tile.hpp"
class Effect{ // Init of Effect
public:
    Effect();
    effect getName();
    target getTarg();
    void actionTile(Tile& tileTarget);
private:
    effect name;
    target targ;
};
#endif // EFFECT_HPP_INCLUDED

Tile.hpp

#ifndef TILE_HPP_INCLUDED
#define TILE_HPP_INCLUDED
#include "TileStatic.hpp"
#include "TileDynamic.hpp"
class Tile{
public:
private:
    TileStatic staticTile;
    TileDynamic dynamicTile;
};
#endif // TILE_HPP_INCLUDED

TileDyanmic.hpp,循环:

#ifndef TILEDYNAMIC_HPP_INCLUDED
#define TILEDYNAMIC_HPP_INCLUDED
#include "Trap.hpp"
#include "Rune.hpp"
class TileDynamic{
public:
private:
    Rune rune;
    Trap trap;
};
#endif // TILEDYNAMIC_HPP_INCLUDED

Ressources.hpp不包括项目文件,它只是常量和一些结构。它们在这里:

#ifndef RESSOURCES_HPP_INCLUDED
#define RESSOURCES_HPP_INCLUDED
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
enum effect{
    ZERO_EFFECT,
    INST_DAMAGE,
    POISON,
    SLOW,
    STUN,
    SILENCE,
    HEAL
};
enum target{
    ZERO_TARGET,
    SELF,
    ENEMY,
    TILE
};
sf::Texture getNoTexture();
const sf::Texture NO_TEXTURE = getNoTexture();
struct coord{
    int x;
    int y;
};
coord getZeroCoord();
const coord ZERO_COORD = getZeroCoord();

#endif//RESSOURCE_HPP_INCLUDED

我希望任何人都知道解决我的问题的方法,我认为这是一个包容性问题。

每个函数的返回类型的首字母都是小写,但类名以大写开头。我认为这就是问题所在。