Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Can';t在player类中创建对象_C++_Visual Studio_Object_Inheritance - Fatal编程技术网

C++ Can';t在player类中创建对象

C++ Can';t在player类中创建对象,c++,visual-studio,object,inheritance,C++,Visual Studio,Object,Inheritance,使用visual studio 2015 enterprise。我有一个Item类Item.cpp。尝试为玩家分配一个设置项,并为其未设置项设置一个向量 class Player{ #include "Player.h" Item items[3]; vector<Item> storedItems; } 职业玩家{ #包括“Player.h” 项目[3]; 矢量存储数据; } 我一直在说定义Item时出错,但我肯定仍然有Item类。当我尝试继承并使“

使用visual studio 2015 enterprise。我有一个Item类Item.cpp。尝试为玩家分配一个设置项,并为其未设置项设置一个向量

class Player{

    #include "Player.h"

    Item items[3];
   vector<Item> storedItems;

}
职业玩家{
#包括“Player.h”
项目[3];
矢量存储数据;
}

我一直在说定义Item时出错,但我肯定仍然有Item类。当我尝试继承并使“Ring”类继承项时,它将再次找不到我对项的定义。我在Player中缺少一些关键语法。h确保在顶部有项.h include文件,如:

#include "Item.h"
class Player {
    Item items[3];
    vector<Item> storedItems;
}
#包括“Item.h”
职业选手{
项目[3];
矢量存储数据;
}

#include“Player.h”
语句是预处理器命令,将被
“Player.h”
文件内容替换。您应该将其放置在类定义之外<代码>包含了 S,通常是源文件和头文件中的第一行。我可以问一下为什么你在一个类声明中间埋藏一个预处理器<代码>包含< /代码>?我得到了一个错误,它被删除了。因此,如果你正在使用另一个类的对象,你需要导入头文件中的其他类来使用它吗?