Thread: Passing a pointer to a member function

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    10

    Passing a pointer to a member function

    I'm new to C++ and I"m not sure how to work my way around this problem.

    I have a function that takes another function as its argument

    function(void (*)(...))

    I'd like the function that I'm passing in to be a member function of another class, but when I try and pass this member function in like this,

    function(someClass->otherFunction);

    I get an error that says

    argument of type `void (someClass:: )(...)' does not match `void (*)(...)'

    So I'm guessing it wants a void* to a function. I just don't know how to set that up. Hope this description is specific enough.

  2. #2
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    unfortunatly you can't pass a pointer to a non-static member as a function pointer.

    There are ways around this though. have a look at the function-pointer.org tutorials
    http://www.newty.de/fpt/fpt.html#defi
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing class member function to pthread_create
    By lehe in forum C++ Programming
    Replies: 6
    Last Post: 03-27-2009, 07:47 PM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  3. Passing pointer into function bug
    By CodeMonkey in forum C++ Programming
    Replies: 4
    Last Post: 04-26-2005, 11:13 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM