Need for initializer list?

Hello all,
When a built-in constructor is available, which can be used to initialize variables, why should there be an initializer list? Are there any differences between the two? Thank you for your time.

KKamudu
Your question is difficult to understand.

Do you want to know the different between assigning the values to variables in the constructor vs Init list? and the benefits?
Yes. What is the difference and the benefits thereof?
In the end, there is no real difference, however, using an initializer list allows you to call the constructors of the objects directly, however if you initialize them inside the body of it, I believe it calls the default constructor, then sets them to whatever you need, which is slightly less efficient.
The potential performance penalty in and of itself is enough of a reason to always use initializer lists unless you absolutely cannot initialize a member that way. Otherwise there is never a benefit to not using them.

And in certain cases, members can only be initialized via initailizer lists (for example references).

Topic archived. No new replies allowed.