Alex Rivera | Logout

Use of constructor in C++

Asked 2011-07-04T18:15:43.880
15

This is very trivial question regarding the use of a constructor in C++. I will present in the form of an interview dialogue (it was difficult to present it in any other forms)

interviewer - what is a constructor?
me - constructor are special functions which makes sure that all objects are initialized before their use.

interviewer - what is an initializer list?
me - that is a list where all the initialization happens. A constructor's body is entered only after all the data members are initialized, or some constructor of all the member objects are called.

interviewer - that means initialization is carried out in initializer list, not inside constructor. But you said constructor initialize the object! Didn't you? Do you want to answer my first question.
me - I think constructor does assignment, it calls assignment operator on already initialized member objects.

So my question to you can be

how initializer list works?

what lies between function's starting address & starting braces [{]?

or just answer me how to convince my interviewer.

Edit
Report

1 Answer

0

The initializer list is part of the constructor. Each constructor has its own.

answered 2011-07-04T18:21:39.393

Your Answer