   C++ problems with polymorphism involving lists
  In my game, I have a function designed to take a reference to a std::list<Sprite> as an argument.  Well, I have many more specialized classes that derive from Sprite, such as Player, Enemy, etc.  I figured that by passing an std::list of one of the derived classes to said function, polymorphism would take care of it.  However, it doesn't.  C++ tells me it can't convert the pointer from Player/Enemy to Sprite.My question is:  is there any way to do what I'm trying to do?  I'm sure there is, and I'm probably just missing something very simple.  Thanks in advance, everyone!   
  You would have your list store (smart) pointers to Sprite instead of just Sprite objects. i.e.: std::list<Sprite *> instead of std::list<Sprite>. Just make sure you remember to call delete on the pointers if necessary as std::list won't do it for you.   ;  Polymorphism in C++ works with pointers or references, not with values. That's why you need to store pointers in the list.   ;  O_O.  Wow, why didn't I think of that?!  Heh, I was thinking that by passing the the list I'd get the effects of polymorphism.  Silly me.Thanks a lot, guys!   ;  The reason this won't work is that std::list<Sprite> and std::list<Enemy> aren't related. Think of them like macros that generates two classes, list_Sprite and list_Enemy. As there isn't a common base class, you don't get runtime polymorphism. As you don't have any virtual functions, there isn't a common interface.Now, you can get something like 'compile time polymorphism' if the function you are calling is templated on the container type or iterator type. This is the style used by the stl to reuse algorithms.Depending on the set of operations, you could wrap your lists in a class, if you need to provide a small set of operations that either extends or changes the constraints/invariants of std::list.   