mercredi 29 avril 2015

How do I get the method pointer of a class, with multiple implementations of that method?

struct A {
    void foo(int) { printf("this is the wrong function\n"; }
    void foo() { printf("this is the right function\n"; }
}

int main() {
    auto method = &A::foo; // c++ why don't you me allow to give argument types?

    A a;
    (a.*method)()
}

I know this little example works fine with just replacing auto with an explicit type, but that is not, what I am looking for. I would like to tell c++ on the right side of the equals, which method I want.

Aucun commentaire:

Enregistrer un commentaire