1

I'm trying to create a template function which calls a member function of a class.

template<typename T>
void call(T owner, void (T::*func)())
{
    (owner.func());
}

and the usage:

Foo a;
call(a, &Foo::printname);

But the compiler returns error C2664. What's the problem?

1 Answer 1

3

func is a pointer-to-member-function; there's a special syntax for calling them:

(owner.*func)();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.