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.
e.g.
class A {
public:
int i;
A* p;
}
int main()
{
A a;
if(a.i ==0 || a.p == 0) //do something
}
The behavior is undefined for the above case. 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.
But I try this in different compilers, and yield different results. My
question is : Is Lippman teaching ISO standard, or compiler-
dependent? Thanks
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.
e.g.
class A {
public:
int i;
A* p;
}
int main()
{
A a;
if(a.i ==0 || a.p == 0) //do something
}
The behavior is undefined for the above case. 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.
But I try this in different compilers, and yield different results. My
question is : Is Lippman teaching ISO standard, or compiler-
dependent? Thanks
Comment