Because I want to store different kinds of object in the same vector. This can only be done by storing the pointers or references to the object and using polymorphism.
Since we are on the subject, why create a vector of pointers in the first place?
Also, I store pointers to objects in a vector when the object is too expensive to copy. (When you use std::vector::push_back(), the copy of the object gets stored.)
However, this extra copy can be avoided by using c++11 'move', .
Both of those statements are inaccurate.
If you change it to a list then you wont get assert about the vector because it isn't a vector any more. A std::list does not use code from within the std::vector. You're probably just getting the same error from a different piece of the std library. Getting the same behviour probably means that you are going past the end of the container rather than corrupting it.
If code with vector still compiles, then something else you are including is pulling in the vector header for you. You should probably not be relying on that.
If you need your vector to hold pointers for reasons of polymorphism, then you might be better off with a boost ptr_container rather than a vector. Otherwise you should problably just store instances directly rather than pointers.
This is the only place I'm using vector in my entire project. and I've searched #include <vector> in my entire solution and there was none.
But now that I already solved the problem, what is the advantage of using a boost ptr vector instead of using a normal vector