This is an extended new question from my last post: How do I use function pointers within this class?
I have three members in my class:
void (X2D::Graphics::OpenGL::Circle::*draw_ptr)(void);
void draw_filled();
void draw_outlined();
This method shows how they are assigned:
void Circle::fill(const bool fill)
{
m_fill = fill;
if (fill)
draw_ptr = &Circle::draw_filled;
else
draw_ptr = &Circle::draw_outlined;
}
Thus, the draw_ptr
function pointer points to either draw_filled()
or draw_outlined()
.
Within the same class, I have the following method:
void draw() { this->draw_ptr; }
However, I placed a debugging point within draw_filled()
, which is where it should be calling, and calling draw()
does not go in draw_filled()
. Because draw_ptr
is parameterless, I'm almost positive it's doing nothing but returning the address to the function. However, I want to call what's in this address.
Using draw_ptr()
does not work, because I get the error:
error C2064: term does not evaluate to a function taking 0 arguments
So, I left it as draw_ptr
.
Am I calling draw_ptr
wrong?
void draw() {
(this->*(this->draw_ptr))();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.