Hello all,
This is my first post and I'm encountering a problem with a program I'm trying to create for a small game. What it involves is basically adding a Player onto a list using std::list.
Now, the issue with that is no matter what I do, only one of the values register so I need help to show you what is going wrong. Here is both General.h and General.cpp
First of all: General.h
That all seems satisfactory with me, that class. Moving onwards we come to General.cpp:Code:class Player { public: int id; string name; void printList(); std::list<Player*> player_list; };
Okay so this seems decent to me and I've browsed many topics of linked-lists to come to this code. So my question to all of you is why is it only say that the list is a mere size of 1 when it should be right up to 11?Code:int main() { Player *entity; int i = 0; while(i != 10) { entity = new Player; entity->id = i; entity->name = "Bobby"; entity->player_list.push_back(entity); i++; } entity->printList(); return 0; } void Player::printList() { std::cout << "There are " << (int) player_list.size() << " players in the linked-list" << endl; return; }
No idea, hopefully someone can assist me as soon as possible! Thanks.



LinkBack URL
About LinkBacks



"