Base{
public:
Base(int i);
virtual void doSomething(int z);
}
Derived:public Base{
public:
Derived(int j);
}
void myFunc(list<Base> myList,int y){
for(list<Base>::iterator it = myList.begin();it!=myList.end();++it){
it->doSomething(y);
}
}
main(){
list<Derived> dList;
myFunc(dList)
}
I can't seem to pass a list of Derived instead of base. I understand that it can be problematic to do this since than one could add different derived types to the list but I only want to change the objects on the list, not add any more objects. I tried playing around with const but that still did not help.I can't use the for_each function since do something gets an argument. Any ideas?