must class member initialization lists in c++ be complete? or can they simply initialize one or two of the member data in a class?
thanks in advance!
They don't have to be complete. You can leave out base classes and non-POD class types that are default constructible, POD-types however will be left uninitialized.
Obviously constant members and references have to be initialized in the member initialization list.
int does have a constructor, see Stroustrup The C++ Programming Language section 6.2.8
int j = int();
This initializes j to 0 (The value of an explicit use of the constructor for a built-in type is 0 converted to that type, thus int() is another way of writing 0. Default constructors for built-in types are important so that templates can invoke default constructors without worry, even for built in types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With