Sekkmer Sekkmer - 1 year ago 120
C++ Question

Visual Studio 'non-standard syntax; use '&' to create a pointer to member'

I was trying to call a function with a function pointer where the function pointer is an class member. I simplifed the code to only show the problem but the foo() function in the oiginal code is already writen so I can not change that.

(In my main code foo is from GLFW (glfwSetKeyCallback) and A is an input handler class.)

#include <iostream>

// this four line can not be changed
typedef void(*fptr)(int);
void foo(fptr f) {

void testOutA(int i) {

class A {
void testInA(int i) {

int main()
foo(testOutA); // work fine as it should be

A * a = new A();

foo(a->testInA); // ERROR

return 0;

ERROR: error C3867: 'A::testInA': non-standard syntax; use '&' to create a pointer to member

Answer Source

The type of the expression a->testInA is a pointer to a non-static member function.

It does not have the same type as fptr, so the compiler emits an error, albeit a cryptic one.

Compilation would pass if testInA were static.

See C++ function pointer (class member) to non-static member function for more details.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download