Short version:
The following code doesn’t compile:
CComBSTR temp;
CMenu().GetMenuString(0, temp, 0);
but this does:
CComBSTR temp;
CMenu().GetMenuString(0, *&temp, 0);
Why?
Full code:
#include <atlbase.h>
extern CComModule _Module;
#include <atlapp.h>
#include <atlwin.h>
#include <atlctrls.h>
int main() {
CComBSTR temp;
CMenu().GetMenuString(0, *&temp, 0);
}
GetMenuString signature (from atluser.h, from WTL):
BOOL GetMenuString(UINT nIDItem, BSTR& bstrText, UINT nFlags) const;
Because the unary operators
&and*can be overloaded, which I guessCComBSTRdoes.* Update: *
For those who wonder how to get the address of a variable whose type has overloaded
operator&there is TR1’sstd::addressof, and a Boost implementation of it for C++03 compatibility.