C++ - 错误:'list'没有命名类型(将对象列为类中的成员变量)
C++ - Error: 'list' does not name a type (list object as member variable in class)
我一直遇到"'xxx'不命名类型"错误,我之前读过的大多数帖子都提到此错误发生在一些依赖项问题中。 但是,我似乎找不到我的。 这是我得到的:
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_ */
玩家组.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_ */
玩家组.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 类中的两个列表成员变量上都收到此错误:
..srcPlayerGroup.h:13:2: error: 'list' in namespace 'std' does not name a type
..srcPlayerGroup.h:14:2: error: 'list' in namespace 'std' does not name a type
提前感谢所有帮助!
我相信你需要在你的PlayerGroup.h文件中#include <list>
,因为它用在那个文件中。
相关文章:
- 你能重载对象变量名本身返回的内容吗
- 为什么我可以使用 memcpy 将一个对象变量复制到另一个对象变量
- 如何使用std::lower_bound比较对象变量,而不使用第二个对象进行比较
- 将私有对象变量与用户输入的变量进行比较
- 具有已定义操作重载的 C++ 非类型化值对象/变量库
- 如何对对象数组进行排序,而不考虑对象变量类型
- 在功能中设置对象变量
- 如何创建对象变量,以便每次分配新的指针
- C++ FileIO 以读取和写入对象变量
- 私下声明的对象变量的突变器/访问器方法
- C++ 列表中的对象变量在迭代过程中不会更新
- 稍后使用私有对象变量时如何初始化数组(初始化对象后)
- 通过向量更改对象变量的值
- C 全局对象变量内存释放
- 基本数据类型变量 VS 对象变量
- C 复制分配运算符,用于参考对象变量
- c++从列表中移除元素,并将其分配给对象变量
- 我们是否需要在C++中同步局部对象变量
- 点运算符和箭头运算符之间的区别 结构对象变量 在 C 或 C++ 中创建树
- 无法访问在 std 回调中传递的对象变量