Reputation: 170469
_com_ptr_ has an overloaded operator&() with a side effect. If I have a variable:
_com_ptr_t<Interface> variable;
How could I retrieve its address (_com_ptr_t<Interface>* pointer) without calling the overloaded operator and triggering the side effect?
Upvotes: 5
Views: 753
Reputation: 116654
I define this utility function:
template<typename T>
T *GetRealAddr(T &t)
{ return reinterpret_cast<T*>(&reinterpret_cast<unsigned char &>(t)); }
Upvotes: 3
Reputation: 179779
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)
Upvotes: 7