You have a vector of pointers, pointers do not have member functions, so you do not call a member function for what is stored in the vector.
The type of object that you get when dereferencing a pointer depends on the type of that pointer. Your vector is a vector of non-constant pointers, so when you remove a pointer from your container, you always get a non-constant reference to the object with a pointer to the object.
If you need a pointer vector, you have two options. You can create a vector<const foo*> instead, and you can never get a non-constant link to any pointer to an object or, if you need to get non-constant links from non-constant instances of your vector, you will need to create an object that contains the vector as a variable private member, and gives you the access you want through the pass-through interface.
If your vector must own objects to which it has pointers, you can consider a simple vector<foo> instead, or if dynamic allocation is required, boost::ptr_vector<foo> .
source share