在D中重载bool运算符(Overloading bool operator in D)

编程入门 行业动态 更新时间:2024-10-24 08:32:53
在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; }

更多推荐

本文发布于:2023-08-05 05:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1427257.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:运算符   bool   operator   Overloading

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!