error C3867: 'TEST::f1': function call missing argument list; use '&TEST::f1' to create a pointer to member

#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"

class TEST
{
typedef int (*F)(int a , int b);
F f;
int f1(int a, int b)
{
return (a+b);
}
int f2(int a, int b)
{
return (a-b);
}
void ass(void)
{
f = f1;
}
};
int main(void)
{
return 0;
}
your F function pointer only works with global or static member functions. It does not work with non-static member functions because they have a hidden 'this' parameter.

You need to either:

1) make f1 and f2 static
or
2) make f1 and f2 global
or
3) change F to accept a TEST function:

 
typedef int (TEST::*F)(int a, int b);


If you do #1 or #3, you'll also have to change how you assign f:

1
2
3
4
//f = f1;   // only OK if f1 is global

// if not global, do this:
f = &TEST::f1;
Topic archived. No new replies allowed.