There are 5 default members in C++ classes. Default constructor, destructor, copy constructor, assignment operator and address operator.
What is an address operator? Is it
className* operator &() {}
?If so, why does the compiler generate this address operator by default (as we already have an address operator in C and we can get the address of an object without this extra overhead)? Is there any special purpose?
You are starting from the wrong premise. The special member functions are (§12 [special]/p1)
The unary
operator &
is not a special member function, and there is no such thing as a compiler generatedoperator &()
function. If you writethen what is used is the built-in
&
operator. No function call or overhead involved. It behaves just like if you took the address of aint
variable.There are programmers who manually overload unary
operator &
. This is usually a spectacularly bad idea.