constructor

hello, my question is what is the big difference between member function and constructor since i can assign data to variable with member function without constructor( i know same name and no return but it is not big difference i think)

They are both functions per say,but the constructor is called when an object is created,the difference is you mainly use constructors to initialise your objects variables and you use functions for completing tasks or working on them said variables.

Constructors are important because you cannot create an object without calling it's constructor
some classes have their constructor as private but normally provide another function which calls the constructor,for example singleton classes would do this.

that's just my take on it,someone with more experience can probably tell you more important needs for a constructor.
Last edited on
firstly thank you, the reason for i ask this question is why we dont use member function to initialize variable, now i understand that constructor to initialize especially, member function for completing tasks. I will search the singleton classes it sounds interesting to me
Topic archived. No new replies allowed.