Click here to Skip to main content
14,272,402 members
Rate this:
Please Sign up or sign in to vote.
See more:
<pre>#include <iostream>
using namespace std;

typedef void (*PFN)();

class A
{
public:
    void foo()
    {
        run(func);
    }

private:
    void run(PFN pfn1)
    {
        pfn1();
    }

    void func()
    {
        printf("run ");
    }
};

int main()
{
    A a;
    a.foo();

    system("pause");
    return 0;
}





while debuging following error shows:
error C3867: 'A::func': function call missing argument list; use '&A::func' to create a pointer to member
Posted
Updated 1-Oct-10 9:51am
v3
Comments
Aescleal 1-Oct-10 15:52pm
   
got rid of the Linux tag - this question is as relevant to Windows, Mobile phones or even embedded systems if they're written in C++
Rate this:
Please Sign up or sign in to vote.

Solution 1

Have a read of this[^].

See if you can't help yourself. :)
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

make
void func()
{
    printf("run ");
}

into the follow static member function
// static member Pointer
static void func()
{
    printf("run ");
}


And your syntax should be correct

or for a member function pointer try this

#include <iostream>
// Example Member function pointer
using namespace std;
class A;
typedef void (A::*PFN)();
class A
{
public:
    void foo()
    {
        run(&A::func);
    }
private:
    void run(PFN pfn1)
    {
        ((*this).*pfn1)();
    }
    void func()
    {
        printf("run ");
    }
};
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100