Function Pointer Problem

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
ok,

seems if I change void (*x)(); to void (MyClass::*x)(); then it works...

is this a scope thing?
Last edited on
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.
Great I have learned something today :)

thanks firedraco!
Topic archived. No new replies allowed.