Turn Desktop View Off
You are here:   HomeC++ ProgrammingClasses in C++c++ - Defining member functions inside or outside the class definition
by Dinesh Thakur Category: Classes in C++

1) Constructor is used for Initializing the values to the data members of the Class.
2) Constructor is that whose name is same as name of class.
3) Constructor gets Automatically called when an object of class is created.
4) Constructors never have a Return Type even void.
5) Constructor are of Default , Parameterized and Copy Constructors.

 The various types of Constructor are as follows:-

1.                Default Constructor:-  Default Constructor is also called as Empty Constructor which has no arguments and It  is Automatically called when we creates the object of class  but Remember name of Constructor is same as name of class and Constructor never declared with the help of Return Type. Means we cant Declare a Constructor with the help of void Return Type. , if we never Pass or Declare any Arguments then this called as the Copy Constructors.

2.                Parameterized Constructor :- This is Another type  Constructor which has some Arguments and same name as class name but it uses some Arguments So For this We have to create object of Class by passing some Arguments at the time of creating object with the name of class. When we pass some Arguments to the Constructor then this will automatically pass the Arguments to the Constructor and the values will retrieve by the Respective Data Members of the Class.

3.                Copy Constructor:- This is also Another type of Constructor. In this Constructor we pass the object of class into the Another Object of Same Class. As name Suggests you Copy, means Copy the values of one Object into the another Object of Class .This is used for Copying the values of class object into an another object of class So we call them as Copy Constructor and For Copying the values We have to pass the name of object whose values we wants to Copying and When we are using or passing an Object to a Constructor then we must have to use the & Ampersand or Address Operator.

Destructor :As we know that Constructor is that which is used for Assigning Some Values to data Members and For Assigning Some Values this May also used Some Memory so that to free up the Memory which is Allocated by Constructor, destructor is used which gets Automatically Called at the End of Program and we doesn’t have to Explicitly Call a Destructor  and Destructor Cant be Parameterized or a Copy This can be only one Means Default Destructor which Have no Arguments. For Declaring a Destructor we have to use ~tiled Symbol in front of Destructor.

If you liked this article, you can also catch us on facebook and Google+


Related Articles (You May Also Like)

{loadposition Classes_in_C++}

What's New and Popular

Search Content

Advance Courses

Basic Courses

Advertise with Us