我如何测试一个对象是否是 D 中特定类的实例?
我如何测试一个对象是否是 D 中特定类的实例?
类似于 Javascript 的 instanceof
关键字?
How do i test that an object is an instance of a particular class in D?
Something akin to Javascript's instanceof
keyword?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
强制转换
。当您尝试转换为不是其实例的子类时(如 C++ 的dynamic_cast),它会返回空引用。Use
cast
. It returns a null reference when you attempt to cast to a subclass it isn't an instance of (like C++'s dynamic_cast).typeid 表达式 可以告诉您实例是否属于某种确切类型(无需考虑继承层次结构):
typeid expression can tell you if instance is of some exact type (without considering inheritance hierarchy):