Get the address of an object that has overloaded o

2019-07-30 04:40发布

operator& for CComPtr is overloaded, which makes my generically written code crash.

I am wondering if there is any way to force a variable into returning the address of it's object?

3条回答
乱世女痞
2楼-- · 2019-07-30 04:54

If you can use boost, consider using: addressof, if you cannot, take a look at the implementation.

查看更多
霸刀☆藐视天下
3楼-- · 2019-07-30 05:09

The solution is hideous:

reinterpret_cast<CComPtr*>(&reinterpret_cast<char&>(ptr))
查看更多
狗以群分
4楼-- · 2019-07-30 05:16

You could cast the CComPtr to a CComPtrBase, which, from what I can gather from the MSDN page, has no overloaded operator. It might look like this:

CComPtr* addr=dynamic_cast<CComPtr*>(&((CComPtrBase)theCComPtr));

I don't know if this works (I can't try it), but it seems like it might, and if it does, it's a little bit better then the reinterpret_cast solution.

查看更多
登录 后发表回答