Why doesn't std::string provide implicit conversion to char*?

前端 未结 7 1358
滥情空心
滥情空心 2020-11-29 06:14

std::string provides const char* c_str ( ) const which:

Get C string equivalent

Generates a null-terminated sequence of cha

7条回答
  •  佛祖请我去吃肉
    2020-11-29 06:30

    Because implicit conversions almost never behave as you expect. They can give surprising results in overload resolution, so it's usually better to provide an explicit conversion as std::string does.

提交回复
热议问题