Hello, I'm still a beginner with C++, while being "well trained" with C. I'm developing a class for a customizable GUI control, which lets you assign a Paint function.
To do that I use function pointers:
Code:
typedef struct
{
CPos pos;
...
}PaintFuncParamsType;
typedef bool (PAINTFUNC*)( PaintFuncParamsType* pParam );
class myButton
{
...
public:
void SetPaintFunc( PAINTFUNC f ){if( f ) m_pf = f;};
void Draw();
....
private:
PAINTFUNC m_pf;
CPos m_pos; //position of the control and size
}
void myButton::Draw()
{
PaintFuncParamsType p;
p.pos = m_pos; //assume "operator =" defined
return (*m_pf)( &p );
}
This seems to work, but I want to know if there's a better way to do it using C++ features.
Also, there are many limitations with this solution, because I can't access to class private members from the called functions, I need to pass them to the called "custom" function using as parameter a pointer to a structured type, as in the previous example.
Thank for any help and suggestion!
BrownB