Hi
Victor Bazarov wrote:
JosephLee wrote:
In Inside C++ object Model, Lippman said there are four cases in
which compile will sythesize a default constructor to initialize
the member variables if the constructor is absent:
1. there is a virtual function;
2. virtual inheritance;
3.base class with explicit default constructor;
4.member object with explicit default constructor.
[...]
If we modify class A to
have any one of the four characeristics, then the member variables
will be initialized in the default constructor sythesysized by the
compiler, as though
A():i(0),p(0){} is defined in the class.
The Standard says that the constructor is trivial if it's implicitly
defined and the class no virtual functions or virtual bases, all
direct base classes have trivial c-tors, all non-static data members
also have trivial c-tors. So, turn that around and you get what
Lippman says.
I disagree. Firstly, it's not correct that if 1-4 is not satisfied
then there will be no default-constructor synthesized:
"If there is no user-declared constructor for class X, a default
constructor is implicitly declared."
"An implicitly-declared default constructor for a class is implicitly
defined when it is used to create an object of its class type. The
implicitly-defined default constructor performs the set of
initializations of the class that would be performed by a
user-written default constructor for that class with an empty
mem-initializer-list and an empty function body"
Secondly, the latter phrase explains that in both of the above cases,
the program will behave as if there was a user-defined constructor
A() {}
This means that neither i nor p will be initialized.
Right. I am not sure with whom you're arguing. The four specific
class are the same as in the Standard. Lippman says that the c-tor
is generated if any of the four is present. The Stadard says that
the c-tor is trivial if none of the four is present. In that sense
Lippman teaches the Standard. No?