Following this and this discussion about zero-initialization, I would like to clarify in which situation these two paragraphs zero-initialization CPP reference occur at the same time:
- As part of value-initialization sequence for non-class types and for members of value-initialized class types that have no constructors, including value initialization of elements of aggregates for which no initializers are provided.
From this paragraph I understand that a class member must have no constructor.
If T is an non-union class type, all base classes and non-static data members are zero-initialized, and all padding is initialized to zero bits. The constructors, if any, are ignored.
But from this one I understand that the constructor of class members, if any (they were supposed not to have), are ignored.
Then, in which case can I define a constructor for a class member and still ignore its constructor?
I made an experiment with these two classes A
and B
, and constructing A{}
calls B()
(obviously) because c=1
. Only B() = default;
will make c=0
.
class B
{
public:
B() : c{1} {}
int c;
};
class A
{
public:
A() = default;
B b;
};
Is it possible? Thank you in advance.