gpt4 book ai didi

C++为什么有类头却有 "Unknown Type"?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:33:48 26 4
gpt4 key购买 nike

<分区>

我有这个头文件,我正在尝试创建 Item 类型的变量。我已经包含了 #include "Item.h",但在编译时我仍然在两个私有(private)变量上遇到 unknown type name Item 错误。

#ifndef PLAYER_H
#define PLAYER_H

#include <vector>

#include "Item.h"

using std::vector;

class Player
{

public:

// constructor
Player( void );

// destructor
virtual ~Player( void );

private:

Item item;
std::vector <Item> inventory;

};

#endif /* PLAYER_H */

这是怎么回事?

这是我包含的 Item.h

#ifndef ITEM_H
#define ITEM_H

#include <string>
#include "Player.h"
#include "GlobalDefs.h"

class Item {
public:
Item();
Item(gold_t v, std::string n);

virtual ~Item();

// Getter
inline virtual gold_t GetValue (void)
{
return value;
}

// Getter
inline virtual std::string GetName (void);

// Getter
virtual std::string GetItemText(void);

protected:
gold_t value;
std::string name;

};

#endif /* ITEM_H */

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com