If the list is to be common among all player objects then try using a static data member.
class Player
{
public:
player(int pid, string pName);
int id;
string name;
void printList();
static std::list<Player*> player_list;
};
// must be defined outside of class declaration
std::list<Player*> Player::player_list;
Player::Player(int pid, string pName)
{
id = pid;
name = pName;
player_list.push_back(this);
}
int main()
{
player *entity;
for (int i = 0; i < 10; i++)
entity = new player(i,"Seif");
entity->printList();
return 0;
}
your printList() member will work fine with no modifications needed.
a brief description of whats going on:
only one copy of the static member player_list exists for all created player objects.
the static data member player_list is not considered part of the objects of type Player. They are externally linked and must therefore be defined outside the class scope.
for more info google for static members.
and on an unrelated note, try to make good use of the constructor as demonstrated above. It will make your life so much easier.