operator-overloading - 在 D 中重载 bool 运算符

标签 operator-overloading d

在 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/

相关文章:

performance - D中的线程上的光纤

function - 艾达函数 "+" "*" "-" "/"

Python——使用现有类方法的特殊方法算术

java - Java 中的通用算术

用于计算金融和计量经济学的 C# 和 NMath

c++ - 如何使用dlang读取二进制文件数据

windows - Langage D 在 Windows 包 tinyredis-2.1.1 上构建错误 : undefined identifier `EWOULDBLOCK` dmd failed with exit code 1

MATLAB:是否可以在 native 构造(单元、结构等)上重载运算符?

c++ - 关于运算符重载的问题

c++ - 在多种编程语言中寻找相似精度的数据类型,例如C/C++、D、围棋