lundi 29 décembre 2014

How do I use function pointers within this class?


I have a class: Circle. It can draw either a filled circle or an outlined circle. Based on its current setting, I want a general draw() method that calls either draw_filled() or draw_outlined().


In my class, I have the following member: void (*draw)(void);


I have two private variables: void draw_filled(); void draw_outlined();


Then, I have the following method:



void Circle::fill(const bool fill)
{
m_fill = fill;

if (fill)
draw = draw_filled;
else
draw = draw_outlined;
}


I get an error on both draw assignments:


error C2440: '=' : cannot convert from 'void (__thiscall X2D::GL::Circle::* )(void)' to 'void (__cdecl *)(void)' 1> There is no context in which this conversion is possible


Normally, I don't use function pointers in classes, so this is new to me. Any help would be appreciated. Thank you.





Aucun commentaire:

Enregistrer un commentaire