Are there any special rules that apply to the unary & operator?
For example, the code:
#include <iostream>
struct X
{
X() {}
void* operator &() { return NULL; }
};
int main()
{
const X x;
std::cout << &x << std::endl;
X y;
std::cout << &y;
}
produces the output
0xbfbccb33
0
I knew this would compile and run like this because of a discussion I’ve had here before, but hadn’t I known this, I would have expected this to fail to compile, because operator & is not declared const.
So it appears that the compiler generates operator &() const regardless of whether operator &() is overloaded or not. Fine, this makes sense, especially with the sample and output.
The question is where is this behavior detailed in the standard?
I’m not looking for answers that re-iterate what I already stated in the question, so please don’t explain how my overloaded operator can’t be called on a const object, because I already know that.
n3337 13.3.1.2/9