如果一个操作符重载为一个C ++类,我怎么可以使用默认操作符? [英] If an operator is overloaded for a C++ class how could I use a default operator instead?

查看:161
本文介绍了如果一个操作符重载为一个C ++类,我怎么可以使用默认操作符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

_com_ptr_ 有一个重载的操作符& ()有副作用。如果我有一个变量:

_com_ptr_ has an overloaded operator&() with a side effect. If I have a variable:

_com_ptr_t<Interface> variable;

如何在不调用重载运算符的情况下检索其地址(_com_ptr_t< Interface> * pointer)副作用?

How could I retrieve its address (_com_ptr_t<Interface>* pointer) without calling the overloaded operator and triggering the side effect?

推荐答案

我看到这种情况弹出一个ISO会议,因为它打破了一些offsetof (LWG 273)。解决方案:& reinterpret_cast< unsigned char&>(variable)

I've seen this case pop up in an ISO meeting as it broke some offsetof() macro implementations (LWG 273). The solution: &reinterpret_cast<unsigned char&>(variable)

这篇关于如果一个操作符重载为一个C ++类,我怎么可以使用默认操作符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆