Short Version:
The main point is that the (complex) state of an instance can be changed by functions that are outside the definition of the class, as such the class can be extended to have all sorts of internal states without polluting the class defintion with many state-setters.
Assume the following code:
class bar
{
virtual void ChangeState()=0;
}
class foo:bar
{
private:
int b;
public:
void ChangeState() {b=3;}
}
What I would like to do is create different functions, then pass them to the function, at runtime, something like
foo.ChangeState(); //b is 3 now
void foo::(?)ChangeState2(){ b=2; };
foo.ChangeState=ChangeState2;
foo.ChangeState(); //b is 2 now
Can such a construct be implemented in C++, without the use of hacks?