C++ - 错误 : 'list' does not name a type (list object as member variable in class)

标签 c++ class stdlist

<分区>

我经常遇到“'xxx' does not name a type”错误,我之前读过的大多数帖子都提到这个错误是由于一些依赖性问题而发生的。但是,我似乎找不到我的。这是我得到的:

GameLib.h

#ifndef GAMELIB_H_
#define GAMELIB_H_

//Structures
struct player_t {
    std::string name;
    int MMR;
};

//Prototypes
void* queueUpPlayer(void*);
int randomMMR();
std::string randomName();

#endif /* GAMELIB_H_ */

PlayerGroup.h

#ifndef GROUP_H_
#define GROUP_H_

class playerGroup {
private:
    std::list<player_t> players;
    std::list<player_t>::iterator it;
    const int totalSize = 10;

public:
    //Constructor
    playerGroup();

    //Destructor
    ~playerGroup();

    //Add
    void add(const player_t p);

    ....
};

#endif /* GROUP_H_ */

PlayerGroup.cpp

#include <iostream>
#include <cstdlib>
#include <string>
#include <cmath>
#include <list>

#include "GameLib.h"
#include "playerGroup.h"

using namespace std;

playerGroup::playerGroup() {}

playerGroup::~playerGroup() {}

void playerGroup::add(const player_t p) {
    if(players.size() >= totalSize) exit(1);
    players.push_back(p);
}

.....

我在 PlayerGroup 类的两个列表成员变量上都收到此错误:

..\src\PlayerGroup.h:13:2: error: 'list' in namespace 'std' does not name a type
..\src\PlayerGroup.h:14:2: error: 'list' in namespace 'std' does not name a type

提前感谢所有帮助!

最佳答案

我相信你需要 #include <list>在您的 PlayerGroup.h 文件中,因为它在该文件中使用。

关于C++ - 错误 : 'list' does not name a type (list object as member variable in class),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21637166/

相关文章:

c++ - 在 std::list 中查找所有匹配的元素

c++ - 从字符串到 GUID 的转换失败

css - 如何在使用 ">"定位类时添加悬停过渡

python - 类没有属性,即使已设置

c++ - 将 std::list::remove_if 与 MyClass 函数一起使用

c++ - 在 std::list<Shape*>::iterator 的指针上调用函数

c++ - 有效的模板参数

c++ - 如何读取 Windows 服务启动的控制台应用程序的输出

c++ - C++ 中循环移位(旋转)操作的最佳实践

Java如何调用另一个类?