khajvah
khajvah

Reputation: 5090

error: expected primary-expression before ')' when passing function-pointer to a function

Following is the function that takes function prototype as an argument:

void callAdded(void (*unitAdded)(rates));

When I do:

callAdded((&ConverterProxy::unitAdded)(rates));

ConverterProxy::unitAdded is a static function and rates is a struct.

Why do I get that error?

Upvotes: 1

Views: 412

Answers (1)

Alan Stokes
Alan Stokes

Reputation: 18964

You should be ok with just callAdded(&ConverterProxy::unitAdded);, assuming there's only one overload with that name. Otherwise you have to cast to the right function type - the syntax you're trying to use just doesn't exist.

Upvotes: 4

Related Questions