检查引用是否指向 C++ 中的特定对象
Check that the reference is pointing to a specific object in C++
如何检查引用是否指向 C++ 中的特定对象?
我的意思是这样的:
int x(0);
int& xR = x;
if(xR == x)
{
//xR is refering to x
}
else
{
//xR is not refering to x
}
他们将有相同的地址。
if( &xR == &x )
{
//xR is referring to x
}
template <class T> T* addressof (T& ref) noexcept
这个函数returns的地址
ref 即使存在重载的引用运算符 (operator&)。
if(std::addressof(xR) == std::addressof(x))
{
yadayadayada
}
如何检查引用是否指向 C++ 中的特定对象?
我的意思是这样的:
int x(0);
int& xR = x;
if(xR == x)
{
//xR is refering to x
}
else
{
//xR is not refering to x
}
他们将有相同的地址。
if( &xR == &x )
{
//xR is referring to x
}
template <class T> T* addressof (T& ref) noexcept
这个函数returns的地址 ref 即使存在重载的引用运算符 (operator&)。
if(std::addressof(xR) == std::addressof(x))
{
yadayadayada
}