I have a base and derived class which derived class is overriding a function in base class
struct Base{
virtual void action(){}
}
struct Derived:public Base{
virtual void action() override{}
}
I have another class that uses Base interface like following
struct Observable{
deque<Base> myObjects;
void addObject(Base &base){
myObjects.push_back(base);
}
void notify(){
for (auto it = myObjects.begin(); it != myObjects.end(); it++) {
it.action();
}
}
}
In main I initialized observer class like this
Derived myDeived;
Observable observable;
observable.addObject(myDerived);
observable.notify();
the problem when I call "notify" and as a consequence it call all "action" function in array It does not call "action" function overrided in Derived but in Base class? please explain me why this happened and how to correct it? Thank you