I am trying to use a function pointer and I am getting this error:
cannot convert from void (__thiscall MyClass::*)(void) to void (__cdecl *)(void)
// Header file - MyClass.h
class MyClass
{
public:
MyClass();
void funcTest();
protected:
void (*x)();
};
// Source file
#include "stdafx.h"
#include "MyClass.h"
MyClass::MyClass()
{
x = funcTest;
}
void MyClass::funcTest()
{
}
(Using: Visual Studio 6)
Can anyone notice anything that I’ve missed?
it’s because a member function is different from a normal function, and hence the function pointers are different. Hence you need to tell the compiler that you want a MyClass function pointer, not a normal function pointer.youneed to declare x as:
void (MyClass::*x)();