Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Whats the difference between using the member initializer list notation, such as used in name.h, and just initializing the members in constructor body?

0
Posted

Whats the difference between using the member initializer list notation, such as used in name.h, and just initializing the members in constructor body?

0

All of the data members are constructed before the constructor body is executed, so initializing the members in the constructor body uses assignment, not initialization (i.e., the object already exists). If no member initializers are given then the no-argument constructor is used. The member initializer notation allows you to control which constructor is used, and to pass data to it.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123