The goal is to have an object which can change its behaivor.
My object is wrapper which should call One::handler() and output "One" but instead it output "from virtual handler" from Situation::handler().
I didn't write the change method because I'm stucking here.
#include <iostream>
class Situation
{
public:
virtual void handler()
{
std::cout<<"from virtual handler()";
}
};
class Wrap
{
private:
Situation _sit;
public:
Wrap(Situation sit)
{
_sit = sit;
}
void call()
{
_sit.handler();
}
};
class One : public Situation
{
public:
void handler()
{
std::cout<<"One"<<std::endl;
}
};
int main()
{
One first;
Wrap wrapper(first);
wrapper.call();
return 0;
}