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 member void (*draw)(void);
I have two private functions: 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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…