Apr 23, 2013 at 3:26pm UTC
I have this base class called Entity, and a class derivied from that called Player. In my MainGamestate class I have a list of Entity.
Why isn't this line working?
1 2
Player player1;
entities.push_back(player1);
ERROR: 'void std::list<_Ty>::push_back(_Ty &&)' : cannot convert parameter 1 from 'Player (__cdecl *)(void)' to 'std::tr1::shared_ptr<_Ty> &&'.
Entity declaration:
std::list<std::shared_ptr<Entity>> entities;
Last edited on Apr 23, 2013 at 3:26pm UTC
Apr 23, 2013 at 3:30pm UTC
Because your vector conain type std::shared_ptr<Entity> and you trying to pass Player to it. Wrap it in shared_ptr<Entity> first
Apr 23, 2013 at 3:41pm UTC
Thanks for answering!
How would I do that?
Last edited on Apr 23, 2013 at 3:41pm UTC
Apr 23, 2013 at 3:48pm UTC
entities.push_back(std::make_shared<Player>());
Last edited on Apr 23, 2013 at 3:48pm UTC
Apr 23, 2013 at 3:57pm UTC
Whoa! Using shared_ptr to point to objects not been created with new
is probably not such a good idea. It will fail to work later when it tries to delete
it.