0

I am learning templates and stuck with the following case:

class ClassA {
   LPCWSTR   Name(void) {...};
   UINT      Name(LPCWSTR name) {...};
   LPCWSTR   Surname(void) {...};
   UINT      Surname(LPCWSTR name) {...};
}

class ClassB {
    template <class T>
    bool SetValue(UINT(T::*Setter)(LPCWSTR), T& object, LPCWSTR value) {
        (object.*Setter)(value)
    }
}

class ClassC : ClassB {
    SomeMethod() {
        ClassA a;
        // Compiler says it can't determine what overloaded instance to choose here.
        SetValue(&ClassA::Name, a, "Mike");
    }
}

How can I pass the right address of the method?

htonus
  • 629
  • 1
  • 9
  • 19

1 Answers1

1

You might specify the one you want that way:

SetValue<ClassA>(&ClassA::Name, a, "Mike");

or

SetValue(static_cast<UINT(ClassA::*)(LPCWSTR)>(&ClassA::Name), a, "Mike");

Demo

Jarod42
  • 203,559
  • 14
  • 181
  • 302