"Nilesh" <dh*******@hotmail.com> wrote in message news:ae**************************@posting.google.c om...
"Stub" <st**@asof.com> wrote in message news:<yX*********************@bgtnsc05-news.ops.worldnet.att.net>... What does it mean that "C++ silently write and call address-of operators"?
It means that you do not have to explicitally write 'operator &', just
as you dont have to write 'operator ='. C++ will silently provide its
own implementation.
Actually that is not true. No implementation is provided by default.
& is just one of those operators that has a native meaning when not
overloaded. This is distinct from the copy assignment operator which
when not declared is implicitly generated.
This is a subtle distinction but examine the following program:
#include <iostream>
using namespace std;
struct B {
B* operator&() {
cout << "B::operator&()\n";
return this;
}
};
struct D : B {
};
int main() {
D d;
&d;
return 0;
}
In this case the &d expression invokes the inheritted B::operator&. If there was an implicitly
generated one (as C++ does for operator=), then the one in B would be hidden and not used.