Parameterised Constructor in C++We know that whenever we create a class, a default constructor gets created, which is invisible mainly in other languages. But when we make a constructor by ourselves, there is flexibility for us to pass the arguments we might think are necessary for the constructor while creating the object in the primary function. Creating a parametrised constructor is pretty simple. We must make our constructor in the class function pass the necessary parameters. C++ CodeOutput: / tm p/ po Rl 42 Ph db .o the value we have created for p1.b is: 10, the value we have created for p1.b is: p1.c = 15 C++ CodeOutput: /tmp/poRl42Phdb.o the values for t1.x is: 20 the values for t2.x is: 15 After destructing the objects which have the value of x is as follows: 15 After destructing the objects which have the value of x is as follows: 20 C++ CodeOutput: after calculating the area of rectangle 1, we have got as 15624 after estimating the size of rectangle two, we have obtained: 28911 |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India