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.
You’re overthinking it and allowing the interviewer to confuse you.
Initializing the members of an object is not the same thing as initializing the object itself. Just because the members have sane values doesn’t mean the object has been constructed. Until the constructor has completed, the object itself has not been properly initialized.