Tuesday, May 20, 2008

C++ : Little Sugar

While creating objects in C++ , in order to initialize objects use the member initialization list. When initialization of a class starts , initialization of its members happens . If the member initialization list is not used the default constructor of all the class members is called even before entering the constructor . Once inside the constructor the copy constructor or operator = is called to initialize the member objects .

On the other hand if member initialization list is used only the copy constructor is called once and hence you prevent the over head of an extra call.

No comments: