gpt4 book ai didi

c++ - 在 if 条件下调用什么重载运算符?

转载 作者:太空宇宙 更新时间:2023-11-03 10:27:20 24 4
gpt4 key购买 nike

来自示例http://www.cplusplus.com/reference/istream/istream/read/有如下语句

ifstream is;
...
...

if (is) { // What overloaded operater of **is** object is called here
....
}

对象的重载运算符叫什么?

最佳答案

从 C++11 开始,有一个到 bool 的转换运算符:

explicit operator bool() const;

在此之前,有一个到void*的转换操作符:

operator void*() const;

后者对任何非空指针求值为 true,否则为 false

关于c++ - 在 if 条件下调用什么重载运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29166568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com