C ++ - Error: "list" does not name the type (list object as a member variable in the class)

I encountered the error "xxx" and did not name the type error, and most of the messages I read before mentioning that this error occurs with some dependency problems. However, it seems that I can not find mine. Here is what I got:

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);
}

.....

I get this error in both list member variables in the PlayerGroup class:

..\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

Thanks for the help!

+3
source share
1 answer

I believe that you need #include <list>PlayerGroup.h in your file because it is used in this file.

+10
source

All Articles