Aug 23, 2010 at 8:13am UTC
Hi,
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)'
1 2 3 4 5 6 7 8 9
// Header file - MyClass.h
class MyClass
{
public :
MyClass();
void funcTest();
protected :
void (*x)();
};
1 2 3 4 5 6 7 8 9 10 11 12 13
// 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?
Last edited on Aug 23, 2010 at 8:14am UTC
Aug 23, 2010 at 8:36am UTC
ok,
seems if I change void (*x)();
to void (MyClass::*x)();
then it works...
is this a scope thing?
Last edited on Aug 23, 2010 at 8:36am UTC
Aug 23, 2010 at 8:57am UTC
No, 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.
Aug 23, 2010 at 11:21am UTC
Great I have learned something today :)
thanks firedraco!