Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.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++ 尝试使用自定义类的对象时,字段的变量声明为void错误_C++_Class_Header Files - Fatal编程技术网

C++ 尝试使用自定义类的对象时,字段的变量声明为void错误

C++ 尝试使用自定义类的对象时,字段的变量声明为void错误,c++,class,header-files,C++,Class,Header Files,我的项目中有此头文件: #ifndef COMMONINCLUDES_H #define COMMONINCLUDES_H #include "utilities.h" #include "textOutput.h" #include "game.h" class Player { public: int score; int poX, posY; }; #endif // COMMONINCLUDES_H 然后在另一个头文件中 #include <commoni

我的项目中有此头文件:

#ifndef COMMONINCLUDES_H
#define COMMONINCLUDES_H

#include "utilities.h"
#include "textOutput.h"
#include "game.h"

class Player
{
public:

    int score;
    int poX, posY;
};

#endif // COMMONINCLUDES_H
然后在另一个头文件中

#include <commonincludes.h>

void turn(Player *currplayer, int mapSize);
#包括
无效回合(玩家*当前玩家,整数地图大小);
并在其自己的cpp文件中匹配函数。我在函数原型的行中得到一个变量field-declated-void-error,并且一个错误表示“Player”没有在这个范围内声明,尽管它包含了头文件。我在这里浏览了一堆其他线程,没有发现一个错误不是针对一个文件中的所有代码,或者是由我排除的某个错误引起的。我知道我以前做过类似的事情,并且成功了,但我不知道这次我做的有什么不同

我还发现,将类定义(复制粘贴,以便我知道我不会更改任何与类定义相关的内容)移动到头文件“utilities.h”中(该头文件包含在上述头文件中),可以使其正常工作


如果这还不够,让我知道,我会拉更多的包括

您有循环标题包含
game.h
包括
commonincludes.h
commonincludes.h
包括
game.h
。你的包含守卫打破了无限包含循环,但他们在
玩家
回合
声明点保持未声明时打破了无限包含循环

根据您目前发布的内容判断,没有必要在
commonincludes.h
中包含“game.h”
。它在那里做什么


注意:使用
#包含“…”
来包含您自己的头文件。
#include
语法用于标准标题。

。推荐。包括完整且逐字的错误消息文本。“另一个标题”的名称是什么?有
turn
的那个。它在game.h文件中。嗯,好的,我明白了。我想我需要从其他cpp文件中调用game.cpp中的函数,所以我在commonincludes中有了游戏的标题,所以它可能是所有可以访问的东西之一。但事实上,现在我想得更多了,我不需要它了,我现在确实明白这是个问题。非常感谢。