Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
您可以将&类中的一元运算符重载为:
&
struct X { void* operator &() { return this; } };
以便它返回一个地址。你将如何在课堂之外重载它:
struct X { }; void* operator &(const X& x) { //how? }
取参数的地址会导致无限递归。
在 C++11 中,有template< class T > T* std::addressof(T& arg).
template< class T > T* std::addressof(T& arg)
标准::地址
您还可以从Boost Utility获得 C++03 的相同功能