检查引用是否指向C++中的特定对象

tra*_*aww 1 c++ equality reference

如何检查引用是否指向C++中的特定对象?

我的意思是这样的:

int x(0);
int& xR = x;
if(xR == x)
{
//xR is refering to x
}
else
{
//xR is not refering to x
}
Run Code Online (Sandbox Code Playgroud)

Dre*_*ann 6

他们将拥有相同的地址.

if( &xR == &x )
{
//xR is referring to x
}
Run Code Online (Sandbox Code Playgroud)