在 C++ 中,您会重载 operator bool() const
。在 Python 中,您将覆盖 __bool__()
。
我可以在 D 中做什么来获得相同的结果?我找不到这方面的任何例子。
最佳答案
在此页面上查找“ bool 运算”:http://dlang.org/operatoroverloading.html
您实现一个成员函数,例如:
bool opCast(T : bool)() {
return bool_result;
}
关于operator-overloading - 在 D 中重载 bool 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33312456/