在 main 函数中调用 foo(“hello”) 时,编译器会将字符串字面量 “hello” 解释为一个 const char 类型的指针*
foo(char *p)
foo(const std::string &p)
foo(const char *p)
int main()
{
foo("hello");
}
执行结果是foo("hello");会匹配foo(const char *p)
在 main 函数中调用 foo(“hello”) 时,编译器会将字符串字面量 “hello” 解释为一个 const char 类型的指针*
foo(char *p)
foo(const std::string &p)
foo(const char *p)
int main()
{
foo("hello");
}
执行结果是foo("hello");会匹配foo(const char *p)