在 D 中重载 bool 运算符
Overloading bool operator in D
在 C++ 中,您会重载 operator bool() const
。在 Python 中,您将覆盖 __bool__()
。
我可以在 D 中做什么来获得相同的结果?我找不到这方面的任何例子。
在此页面上查找 "Boolean Operations":http://dlang.org/operatoroverloading.html
你实现了一个成员函数,如:
bool opCast(T : bool)() {
return bool_result;
}
在 C++ 中,您会重载 operator bool() const
。在 Python 中,您将覆盖 __bool__()
。
我可以在 D 中做什么来获得相同的结果?我找不到这方面的任何例子。
在此页面上查找 "Boolean Operations":http://dlang.org/operatoroverloading.html
你实现了一个成员函数,如:
bool opCast(T : bool)() {
return bool_result;
}