小编shu*_*ura的帖子

转换运算符作为独立函数

为什么C++要求用户定义的转换运算符只能是非静态成员?为什么不允许像其他一元运算符一样使用独立函数?像这样的东西:

operator bool (const std::string& s) { return !s.empty(); }
Run Code Online (Sandbox Code Playgroud)

c++

25
推荐指数
1
解决办法
6497
查看次数

标签 统计

c++ ×1