Rudresh
Answered On : Jan 18th, 2012
For a global objects and static class members, the initializer list doesnt invoke any code on run time. (Initialization data is stored directly in the binary).
If you are initializing a lot of objects, or if the constructor code is expensive / large, this can make a notable difference at load time.
As said, this is true only for plain old data, i.e. everything that can be initialized with an initializer list in
Login to rate this answer.
abc
Answered On : Feb 5th, 2012
--> initializer list is used with constructor when any const datas are used in a class.
--> bcoz, as we known const var should be initialized while declaring.
--> the class gets memory allocation oly wen an obj is created for it.
--> when an obj is created, compiler internally calls constructor, which will initialize the const using the initiailizer list.
Syntax:
classname (arg1,arg2....):initializer_list
eg:
car (char*name,float price,int reg_id):reg_id(i)
Login to rate this answer.
For some object the initialized list is necessary because they are const or do not have default constructors. However, the main advantage is that if you construct the object in the constructor body then you will be creating a temporary object AND calling the assignment operator as opposed to creating it in the initialiser list where you will just be calling the constructor.

1 User has rated as useful.
Login to rate this answer.