Jump to content
  • Advertisement
Sign in to follow this  
RiBi

Function pointers and classes [SOLVED]

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

Hello, I just recently run into a problem with function pointers. I though I understand their concepts and used them many times already. However, until now, I have never tried to do the following:
class CLASS;

void (CLASS::*FOO)();

class CLASS {
public:
    void foo() {
        printf("foo");
    }

    void foo2() {
        FOO=&CLASS::foo;
        FOO();        
    }
};

int main() {
    CLASS c;
    c.foo();
    c.foo2();

    return 0;
}



I expected the given code to output two "foo" messages, but on the line with FOO() statement, the compiler informs me with "error C2064: term does not evaluate to a function taking 0 arguments" error message. I went through many articles about function pointers and classes, but none of them have solved my problem so far. What am I doing wrong? Thank you in advance. [Edited by - RiBi on July 8, 2007 2:36:17 AM]

Share this post


Link to post
Share on other sites
Advertisement
foo is a member function (in Object-Oriented jargon, it is called a "message"). When you call it, you must specify an instance on which it is called (the object to which you want to send the "message").

(this->*FOO)();

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!