Constructor and Destructor in c++

today we are going to discuss about cplusplus constructors and destructors ok we are going to discuss about constructors and destructors now what is called construct and what is called destructor before going to discuss constructors and destructors now I am going to give one small example first of all why we need the constructor ok the set of all I am going to show you one example later I am going to clear the Constructor and destructor stop me now watch this example suppose there is a class ok hashinclude iOS simulator some class test later IND equal to 10 now I should share a week actually there call data member and variable possible with pen and a well insulated with problem is C plus plus compiler never close this kind of initialisations because of data members specially Private data members ok the data members of a class should be should be initialised through the member functions of same class Ok actually in C plus plus there is a rule what is that means the data member should be initialised through the member functions of same class which is called Data Hiding concept ok but actually was sending initialising the values directly that’s why this concept is not allowed in C plus plus next how to initialise then here are going to declare like the way you are creating object object function when is not a Member function how it is possible only because of constructor function function function which is itself and which is called automatic initialisation of object ok this constructor is a special member which is used to initialise an object itself and this process called automatic initialisation of object now what are the and what are the benefits of construct ok next year the first. Water is used numbers are automatically in place and when they are initialised when the object of that class is created now here the point is when object is created automatically constructor is invoked on the data members are initialised for this what are the rules we have to follow the first rule for constructor is the name should be equal into class name the name should be equal and two classmates for example hair wash it or class name is what test and data members and now in previous exam for I have used while get actually classname test Member function and get that means there is no relation but here for construction the first rule is what the constructor should be similar to the classmates because of constructor meaning is what it is a special Member function it is a special Member function whose name is similar to the class name and which is used to initialise the object number that’s why I hear test ok ok its close now is it here class name is best and Member function name also test and hear what it here there is no why the integer or float because of there is another rule for construct what is that means constructor never returns any value or constructor never have any return data types including wild ok including white it is the another important rule for constructor first release what constructor name should be similar to the class and second rules constructor never having any return value and return data types including word including Why this Why don’t start with why the integer or anything just start with S III ok find it is a second ok fine next a value 10 and we value 20 no bracket close in my example it is called what constructor oK it is a share what happens going for main function object is created

Speak Your Mind