All About C++

Get Pure Concepts of C++

Sunday 26 June 2016

What is constructor in c++,default and argument constructor

Constructer without any argument (default constructor).
       Let name of class is “list” and “size” and “fill” are two data members(variables) and "arr" is array  in a class then constructor without argument will be                                                           
list :: list()
 {             size=10;
arr=new int [size];
             fill=-1;
 }
Here we give values to size=10, and fill=-1, this is a default constructer,
Constructer with one parameter.
Let name of class is “list” and “size” and “fill” are two data members (variables) and "arr" is array in a class then constructor with one argument will be
list :: list(int num)
 {            size=num;
             arr=new int [size];
             fill=-1;

 }

No comments:

Post a Comment