Mustafa Ismail

I have a pointer definition as such:

Code Block

typedef bool (WorkerClass::*pf)(std::string &, std::string &);

for Method signature:

Code Block

bool fncSame( std::string &x , std::string &y );

Why does the following fail

Code Block

std::string a("a");


WorkerClass::pf pfn = &WorkerClass::fncSame;

It gives me the following error:

error C2064: term does not evaluate to a function taking 2 arguments

Re: Visual C++ Language Function Pointer problems


You shouldn't call the function unless it has been assigned, and it does look like you're doing that in your example. Also, I don't quite get where you're headed by writing "WorkerClass:: pf pfn =".

In either case, as those may be mere typos, what you want to be doing is call the function on an instance, such as

(instancePtr->*pfn)(&a, &a);

or, if the instance isn't a pointer:

(instance.*pfn)(&a, &a);