见过以下示例: https://godbolt.org/g/yYgZox
#include <iostream>
struct A {
operator void* (){ return nullptr; }
};
A a;
A& getA () {
return a;
}
int main(int, char**)
{
int x = 0;
// this works
if (std::cout << x) {
return 1;
}
// this works only because we have operator void* defined
if (getA()) {
return 2;
}
return 0;
}
为什么编译器在定义为成员函数时可以对void *进行引用?