The problems I found on the Forum recently have changed my previous incorrect views in this regard and I will share them with you.
It is said that this question has a high chance of being asked during the interview. Fortunately, I have never encountered it.
The popular view is:
Class Empty {};
Equivalent:
Class Empty
{
Public:
Empty ();
Empty (const Empty &);
~ Empty ();
Empty & operator = (const Empty & rhs );
Empty * operator &();
Const Empty * operator & () const;
};
Based on the descriptions in Chapter 12 Special member functions in ISO/IEC 14882: 2003 (E), it can be determined that
The default constructor copy constructor operator = is implicitly declared. Empty * operator & () and const Empty * operator & () const; are not implicitly declared.
The source of the error is translated by Hou Jie's simplified Chinese Simplified "negative c ++, 2nd".
Clause 45: Find out the functions written and called by C ++ behind the scenes
When is an empty class not an empty class? ---- When the C ++ compiler passes through it. If you do not declare the following functions, the considerate compiler will declare its own version. These functions are: A copy constructor, a value assignment operator, a destructor, and a pair of access operators. In addition, if you do not declare any constructor, it will also declare a default constructor for you. All these functions are public. In other words, if you write:
Class Empty {};
This is the same as writing:
Class Empty {
Public:
Empty ();
Empty (const Empty & rhs );
~ Empty ();
Empty & operator = (const Empty & rhs );
Empty * operator &();
Const Empty * operator & () const;
};
Some readers have raised a question to Scott Meyers, the author of the book. Scott Meyers also thinks that the answer above is problematic.
The author's explanation of this problem is as follows:
! 2/10/00 ic 212 A class declaring no operator & function (s) 9/10/01
Cxh 213 does NOT have them implicitly declared. Rather,
245 compilers use the built-in address-of operator
246 whenever "&" is applied to an object of that
Type. This behavior, in turn, is technically
Not an application of a global operator &
Function. Rather, it is a use of a built-in
Operator.
So far, I believe that the reader has an answer.
From Jiang Yafeng's CSDN blog