在此代码中:
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);
}
如果我取消注释display_greeting()
的代码,则重载解析会在编译时失败,从而导致错误
no matching function for call to 'mem_fn(<unresolved overloaded function type>)'
auto greet = std::mem_fn(&Foo::display_greeting);"
^
如何解决此问题,以便我可以同时拥有display_greeting
个函数?