Skip to main content
gamedev.net
🔒 Locked

pointer to member-function

Started by merwin May 11, 2004 at 4:59 PM 2 replies 750+ views
Original Post
merwin
merwin
I've a tempplated class CDrawRectangle, which has a function pointer to a function of this class:
template<class T>
class CDrawRectangle{

// function pointer to a member-function of this class

void (*DrawPixel)(int, int, int);

// one way to draw a pixel

void DrawPixelQuick(int x, int y, int color);

// another way to draw a pixel

void DrawPixelSlow(int x, int y, int color);
if I try to assign DrawPixel to one of the member function (within another member-function of CDrawRectangle) I get a syntax error: cannot convert from 'void (__thiscall CDrawRectangle::*)(int,int,int)' to 'void (__cdecl *)(int,int,int)' When I change the declaration of DrawPixel to: void (CDrawRectangle::*m_DrawPixel)(int, int, int); vc++ says "term does not evaluate to a function" and points to a line where I make an call to DrawPixel. It doesn't complain when I assign the member-function to the function-pointer. I don't understand why vc++ complains so much ;(, but I hope that my problem is clear and someone can give me some advice [edited by - Merwin on May 11, 2004 6:03:16 PM]
Jingo
Jingo

struct example
{
void function(){}
};

int main()
{
example one, *ptwo = &one
void (example::*pfunction)(void) = &example::function;
(one.*pfunction)();
(ptwo->*pfunction)();
}


[edited by - Jingo on May 11, 2004 6:07:19 PM]
Archimage
Archimage
Beat me to it

Also it might be worth checking out

http://www.function-pointer.org/functor.html

which I found on an earlier thread (looks as though it covers the basics).

Yours,

Archimage
(Ann-Marie Ratcliffe)


[edited by - Archimage on May 11, 2004 6:10:06 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.