在D中重载bool运算符(Overloading bool operator in D)
在C ++中,您将重载operator bool() const 。 在Python中,您将覆盖__bool__() 。 我可以在D中做些什么来达到相同的效果? 我找不到任何关于此的例子。
In C++ you would overload operator bool() const. In Python, you would override __bool__(). What can I do in D to achieve the same result? I can't find any examples on this.
最满意答案
在此页面上查找“布尔运算”: http : //dlang.org/operatoroverloading.html
您实现了一个成员函数,如:
bool opCast(T : bool)() { return bool_result; }Look for "Boolean Operations" on this page: http://dlang.org/operatoroverloading.html
You implement a member function like:
bool opCast(T : bool)() { return bool_result; }更多推荐
发布评论