Example & Tutorial understanding programming in easy ways.

Define parametrized constructor in C++

What is constructor?
Basically, constructor is the special type of function in class which can automatically called at the time of object creation.
or,
constructor is the function which will called when we create any new object.

Constructor property:
-Class name and constructor name should be same.
-There is no return type of constructor like void,int etc.

Type of constructor:
1.Default constructor
2.Parametrized constructor
3.Copy constructor

2.Parametirized constructor:
This constructor are those in which we can pass an argument.

program:

#include < iostream>

using namespace std;
class Myclass
{
public:
Myclass(int a,int b)
{
cout<<"This is Parametirized constructor"<< endl;
cout<<"Sum is: "<< a+b;
}
};
int main()
{
Myclass obj(3,4);
return 0;
}


output-

This is parameterized constructor
Sum is: 7




Read More →