term does not evaluate to a function taking 1 arguments

Problem #1: The name of the second argument and the type of the second argument are swapped somehow. It should be:

      DoSomething* doSomething
//    ^^^^^^^^^^^  ^^^^^^^^^^^
//    Type name    Argument name

Instead of:

    doSomething* DoSomething

Which is what you have.

Problem #2: You need to add a couple of parentheses to get the function correctly dereferenced:

    (doSomething->*pt2Func)("test");
//  ^^^^^^^^^^^^^^^^^^^^^^^

Eventually, this is what you get:

void foo(
    void (DoSomething::*pt2Func)(const std::string&), 
    DoSomething* doSomething
    )
{
    (doSomething->*pt2Func)("test");
}

And here is a live example of your program compiling.

Leave a Comment