引子
昨天在某个群看到了这样一段代码:
#include <iostream> #include <string> using namespace std; void foo(string str) { cout << "string" << endl; } void foo(bool b) { cout << "bool" << endl; } void foo(char c) { cout << "char" << endl; } int main() { foo("hello, world"); return 0; }
现在的问题是,这段程序的输出是什么?或者说,foo("hello, world");
调用的究竟是哪个函数?
要解决这个问题,我们就要详细讨论一下函数重载的规则。
继续阅读浅谈函数重载规则