I am trying to implement Observers and a Subject design pattern...
I have a object Subject, with a vector of pointers to Observers. Each Observer has a pointer to a function. How do I call it?
In this class, it's defined the function that I want to call
class functions_class
{
static bool getVal(){
return true;
}
};
In this class, the vector containing the observer is defined
class Subject
{
vector<Observer*> mViews;
public:
void addObserver(Observer *o)
{
mViews.push_back(o)
}
};
In this class, the function pointer is stored. There is a function to call this pointer
class Observer
{
typedef bool(*boolPtr)(void);
boolPtr mPtr;
Observer(boolPtr ptr)
{
mPtr = ptr;
}
bool call()
{
return (mPtr)();
}
};
This is where objects are created
Subject s;
Observer o(functions_class::getVal);
s.addObserver(&o);
QUESTION......... How do I call the function pointer in observer?? I'm using a generic function in observer, but I can't make it work.
I tried:
(s.mViews[0].call)()
Any idea?
Is it also possible to cast the output of the function call to an uint32_t?
s.mViews[0]->call();