The document discusses different types of constructors in C++ including default, parameterized, copy constructors, and constructor overloading. It provides examples of how each type of constructor is defined and used to initialize object data members. The key points are:
1) Constructors are special member functions that initialize objects and are invoked when an object is created. They have the same name as the class but no return type.
2) A default constructor takes no parameters and initializes data members with default values. A parameterized constructor initializes members with values passed as arguments.
3) A copy constructor initializes an object using the values from another object of the same class. Constructor overloading allows defining multiple constructors in a class.
3. 1. Special member function to initialize the
objects of its class.
2. Itsname is same as the class name.
3. It is invoked wheneverthe object is
created.
4. It has no return type, so can’t use return
keyword.
4. Class integer
{
Int m,n;
Public :
Integer();//constructor
Declared
……
};
//Constructordefinition
Integer ::integer()
{
m=0;
n=0;
}
5. 1. Theyshould be declared in the public section.
2. Theyare called automatically when the object are
created.
3. Theydo not have return type even void
4. Theyhave same name as the class name.
6. 1. They takes no parameters.
2. They are called internally by the compiler
whenever the object are created.
3. There is no need to call it explicitly
8. 1. These are the constructor that take arguments.
2. Theyinitialized the object data members by the value
which is passed asarguments.
3. Theyare invoked when we pass the arguments tothe
object when they are being defined.
4. Example:integer int1(2,5);
10. 1. Itis used to declare and initialized
an object from another object.
2. Ittakes reference to an object of
the same class as itself as an
arguments.
13. 1. Constructor overloading is the process of
defining more than one constructor in the
same class.
2. C++permits us to use multiple constructor in
the same class.