为什么*&x与x不一样?

Meh*_*dad 8 c++ pointers reference

精简版:

以下代码无法编译:

CComBSTR temp;
CMenu().GetMenuString(0,   temp, 0);
Run Code Online (Sandbox Code Playgroud)

但这样做:

CComBSTR temp;
CMenu().GetMenuString(0, *&temp, 0);
Run Code Online (Sandbox Code Playgroud)

为什么?


完整代码:

#include <atlbase.h>
extern CComModule _Module;
#include <atlapp.h>
#include <atlwin.h>
#include <atlctrls.h>

int main() {
    CComBSTR temp;
    CMenu().GetMenuString(0, *&temp, 0);
}
Run Code Online (Sandbox Code Playgroud)

GetMenuString签名(来自atluser.hWTL):

BOOL GetMenuString(UINT nIDItem, BSTR& bstrText, UINT nFlags) const;
Run Code Online (Sandbox Code Playgroud)

K-b*_*llo 11

因为一元运算符&并且*可以重载,我猜CComBSTR这样做.

*更新:*

对于那些想知道如何获得类型已经过载的变量的地址的人来说,operator&有TR1的std::addressof,以及它的Cost 03兼容性的Boost实现.