I have some problems always when I'm trying to work with pointer-to-function. I need to create some that can be called from another class. But maybe I don't know how to make it. This is the code I've written:

// UIRWin is the class that I need to call the MTP::Application::Start function from
// MTP::Application is in RenderEngine
UIRWin->mExtVoid = &MTP::Application::Start;

RenderEngine[.h] contains class that have this function:

class Application
virtual void Start(bool);


typedef void (MTP::Application::*pVoid)(bool);
pVoid mExtVoid; // set in Editor
if (mExtVoid)

So everytime I try to compile this, I get this error:
error C2064: term does not evaluate to a function taking 1 arguments

Please, where I'm wrong? :icon_cry:

8 Years
Discussion Span
Last Post by Narue

>Please, where I'm wrong?
You're mixing up pointers to functions and pointers to member functions. A pointer to a member function (which is what you want) must be called on an existing object:

MTP::Application obj;

(obj.*mExtVoid) ( true );

So how can I create a pointer to function type if the function I want to call may be from different classes. For example:
class ClassOne
void functionOne(bool);
class ClassTwo
void functionTwo(bool);

typedef void(*pVoid)(bool);

and then set it like this:
pVoid mExternalVoid = ClassOneVar.functionOne;

pVoid mExternalVoid = ClassTwoVar.functionTwo;


>So how can I create a pointer to function type if the
>function I want to call may be from different classes.
You'll need to think of another way to accomplish what you want. The short answer is that pointers to members don't allow you to do this because a pointer to a member is intrinsically bound to a single class. It helps to understand that pointers can hold more information than just an address.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.