我一直在开发一个基于文本的冒险游戏,我希望将个别项目存储为几个结构的实例:Item
,Armor
和Weapon
。问题是,即使我的Item
结构有效,每当我编译时,我会在几个const NoArmor / Weapon占位符上出现Armor does not name a type
和Weapon 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枚举。