Jump to content
  • Advertisement
Sign in to follow this  
Kalnos

Pointer to member function?

This topic is 2949 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

Hey guys, I'm playing around with DragonfireSDK (iphone Cpp dev) and I've come across a problem.

The SDK utilizes callback functions that are referenced when you set up the touch area, and I'm having trouble with the syntax for making these callbacks member functions. E.g:



class Foo {
public:

Foo()
{
TouchArea(image, x, y, Callback, id);
}

private:

int CallBack(int, int, int, int);


};




In this example.. if you run the problem the compiler will ask for a missing argument list, as it thinks I'm trying to execute the function.

If I change TouchArea to something like:

TouchArea(image, x, y, &Foo::Callback, id);

Then I get:


error C2665: 'TouchArea' : none of the 3 overloads could convert all the
argument could be 'int TouchArea(char *,int,int,int (__cdecl *)(int,int,int,int),int)
while trying to match the argument list '
(char *, int, int, int (__thiscall Foo::* )(int,int,int,int), int)'



Any help in showing me what's wrong with my syntax, or what I should read is appreciated!

Share this post


Link to post
Share on other sites
Advertisement
class Foo {
public:

Foo()
{
TouchArea(image, x, y, this.Callback, id);
}

private:

int CallBack(int, int, int, int);


};

could it work?

Share this post


Link to post
Share on other sites
If you're using an SDK that is designed to accept function-pointers, then there's no way you can give it a member-function-pointer instead -- these are fundamentally different.
In order to call a function-pointer, you just call it.
In order to call a member-function-pointer, you need to call it along with a this pointer, which the SDK won't have.

Share this post


Link to post
Share on other sites
Non-static member functions need a class instance to operate on. As such, they cannot be used interchangeably with pointers to non-member or static member functions.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!