This question already has an answer here:
In this code:
struct Foo {
/*void display_greeting() {
std::cout << "Hello, world.\n";
}*/
void display_greeting(int i) {
std::cout << "Hello, world.Greeting #" << i <<std::endl;
}
};
int main() {
Foo f;
auto greet = std::mem_fn(&Foo::display_greeting);
greet(f, 1);
}
If I uncomment code for display_greeting(), the overload resolution fails at compile time giving error
no matching function for call to 'mem_fn(<unresolved overloaded function type>)'
auto greet = std::mem_fn(&Foo::display_greeting);"
^
How do I fix this issue, so that I can have both flavors of display_greeting func?
Aucun commentaire:
Enregistrer un commentaire