Classes: In-class member initializers


Provide default values

  • Useful for providing default values for its members. This also reduce the number of members that needs to be initialized per constructor.
  • In case the member contains a default initialization and is also set on constructor, the constructor will override the value.



Initialization should be done for all levels in order to work properly.

Below we can see that the class Test contain an in-class initialization, but that class does not have the initialization created further.


Quiz – What values will take a and b after the object construction?




You may also like...

Leave a Reply