0

I am trying to create a function pointer to another function in c++.

This is what I have so far:

LONG (*function)(LPSTR,LPVIPERVAR4,LONG)=&CWilExtender::DllVarHandler;

When I try to compile my program, I get this error:

.\MyExtender.cpp(132) : error C2440: 'initializing' : cannot convert from
'LONG (__thiscall CWilExtender::* )(LPSTR,LPVIPERVAR4,LONG)' to
'LONG (__cdecl *)(LPSTR,LPVIPERVAR4,LONG)'
        There is no context in which this conversion is possible

I don't know how the DllVarHandler was defined, and I don't know how to reproduce the type for the function pointer.

How do I change the (_cdecl *) to match (__thisscall CWilExtender::*)?

Specifically, what does LONG (__thiscall CWilExtender::* )(LPSTR,LPVIPERVAR4,LONG) mean and how do I write that as the function pointer's type?

Thanks.

Dan
  • 331
  • 1
  • 12
  • 3
    possible duplicate of [c++ Function member pointer](http://stackoverflow.com/questions/17304659/c-function-member-pointer) – Oliver Charlesworth Jun 28 '13 at 02:57
  • 1
    That error message is telling you what type it's expecting. – tadman Jun 28 '13 at 02:58
  • In C++ you can use virtual methods and therefore write code that is both easier to read and also avoids this problem. Use and interface instead. – Ed Heal Jun 28 '13 at 03:01
  • If you don't have a good C++ reference, you're going to have a really hard time getting the hang of this. Even seasoned programmers get this sort of thing wrong if they're not careful. – tadman Jun 28 '13 at 03:01
  • Such a pretty snippet of code. I think the problem is that the function pointer needs a CWilExtender object to actually call DllVarHandler, since DallVarHandler is not a static function. Check example http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr034.htm – dchhetri Jun 28 '13 at 03:02
  • 2
    @OliCharlesworth is correct, you're trying to express a member function pointer, which is different than a function pointer. Read the article to which Oli is linking. – crowder Jun 28 '13 at 03:05

1 Answers1

0

Thanks to the comments by @OliCharlesworth and @user814628, I solved my problem.

The correct code should be:

LONG (CWilExtender::* function)(LPSTR,LPVIPERVAR4,LONG)=&CWilExtender::DllVarHandler;

Thanks for being so quick to help!

Dan
  • 331
  • 1
  • 12