Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Marty

Setting Up Class Function Pointers

This topic is 6923 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Rookie in need of help here. How do I set up a pointer to a class function in C++? e.g. Say I have a directdraw wrapper class called ''ddraw'', which has two blit functions, ''bltfullscreen()'' for a fullscreen mode blit, and ''bltwindow()'' for a windowed mode blit. How do I then setup a function pointer ddraw->blt() which calls the relevant function. By setup, I mean how do I define, and how to I assign the pointer variable? Thanks, Marty.

Share this post


Link to post
Share on other sites
Advertisement
Ok let''s say this is your class:

class ddraw {
public:
void bltfullscreen(void);
void bltwindow(void);

void (ddraw::*blt)(void);
};

Then blt should be a function pointer that can be assigned either bltfullscreen or bltwindow.

To use it:

int main() {
ddraw * d = new ddraw();
d->blt = ddraw::bltfullscreen;
(d->*(d->blt))();
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!