Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ - Error: 'list' does not name a type (list object as member variable in class) [closed]

Tags:

c++

class

stdlist

I have been running into the "'xxx' does not name a type" error a lot and most posts I've read before have mentioned that this error occurs with some dependency issues. However, I can't seem to find mine. Here's 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'm recieving this error on both the lists 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 all the help in advance!

like image 751
Joe Avatar asked Feb 07 '14 20:02

Joe


People also ask

How to fix Class A does not name a type error?

This was throwing the same compiler error message mentioning that Class A does not name a type. There was no circular dependency in my case. So, be careful while naming classes and declaring enums (which might be visible, imported and used externally in other files) in C++. Also, this can be fixed by switching from enum to enum class.

What does TypeError ‘list’ object is not callable mean?

TypeError: ‘list’ object is not callable. In python, we get this error when we pass the argument inside the print statement, the code contains the round bracket to print each item in the list due to which we get this typeerror. Example: my_list = ["Kiyara", "Elon", "John", "Sujain"] for value in range(len(my_list)): print(my_list(value))

What are some common errors in Oracle listview?

And got the following errors (more than that, but all of them with the same reason): ERROR: Variable FDtotalFNF in list does not match type prescribed for this list. ERROR: Variable IDtotalFNF in list does not match type prescribed for this list. ERROR: Variable ODtotalFNF in list does not match type prescribed for this list.

What are the types of TypeError in Python?

TypeError: unsupported operand type (s) for +: ‘int’ and ‘str’. 1. TypeError: ‘list’ object is not callable 2. TypeError: unsupported operand type (s) for +: ‘int’ and ‘str’ 3. Python object has no attribute 4. TypeError: python int object is not subscriptable


1 Answers

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

like image 84
Alex Johnson Avatar answered Oct 23 '22 02:10

Alex Johnson