c++ char 自动变成了 bool 类型

创建日期: 2024-03-05 14:28 | 作者: 风波 | 浏览次数: 13 | 分类: C++

参考:https://stackoverflow.com/questions/57101717/prevent-string-literals-from-being-converted-to-bool-versus-stdstring

问题:有两个重载函数 int a(std::string a)int a(bool b) ,结果在调用字符串版本的 a("abc") 的时候,编译器自动去调用 int a(bool b) 了。

解决:直接声明一个 int a(const char *) 函数,然后里面再调用 a(std::string(a))

13 浏览
10 爬虫
0 评论