(Struct)没有命名类型错误

时间:2017-03-30 03:03:40

标签: c++ struct

我一直在开发一个基于文本的冒险游戏,我希望将个别项目存储为几个结构的实例:ItemArmorWeapon。问题是,即使我的Item结构有效,每当我编译时,我会在几个const NoArmor / Weapon占位符上出现Armor does not name a typeWeapon does not name a type错误。我已经通过其他主题查看了这个主题,但没有一个证明是适用的或有用的。

以下是我所指的代码:

#ifndef ITEMS_H_
#define ITEMS_H_

#include <string>
#include "Types.h"

using namespace std;

struct Item {
    string name;
    double weight;
    double value;
    ItemType type;
};

struct Armor {
    Item base;
    double armorMod;
    WeaponType weakness;
    WeaponType resistance;
    ArmorType armorType;
};

struct Weapon {
    Item base;
    double damageMod;
    double agilityMod;
    WeaponType weaponType;
};

const Item NoItem = {"_NO_ITEM_", 0, 0, NoItemType};
const Armor NoArmor = {NoItem, 0, NoWeaponType, NoWeaponType, NoArmorType};
const Weapon NoWeapon = {NoItem, 0, 0, NoWeaponType};


#endif /* ITEMS_H_ */

编辑:Types.h导致问题

types.h中:

#ifndef TYPES_H_
#define TYPES_H_

enum ItemType {
    NoItemType,
    Food,
    Misc,
    Weapon,
    Armor
};

enum ArmorType {
    NoArmorType,
    Helmet,
    Tunic,
    Chestplate,
    Bracers,
    Gloves,
    Gauntlets,
    Pants,
    Greaves,
    Robes,
    Sabatons,
    Boots
};

enum WeaponType {
    NoWeaponType,
    Sword,
    Dagger,
    Hammer,
    Axe,
    Staff,
    Bow
};

enum ClassType {
    NoClassType,
    Knight,
    Warrior,
    Thief,
    Blacksmith,
    Lumberjack,
    Mage,
    Archer
};

enum RaceType {
    NoRaceType,
    Human,
    WoodElf,
    Orc,
    DarkElf,
    Dragonling,
    Dwarf
};

enum SpecialtyType {
    NoSpecialtyType,
    TwoHand,
    OneHand,
    Archery,
    Necromancy,
    Conjuration,
    Destruction
};



#endif /* TYPES_H_ */

解决:问题是包含相同值(武器和护甲)的ItemValue枚举。

0 个答案:

没有答案