Constructor
Constructor
Constructor has special member function which is used to initialize value of variable inside an object.
Major point:
3 types of constructor.
1. Default
2. Parameter
3. Copy
Default constructor:
Class demo
Int a,b;
Public;
Demo ()
A=10;
B=20;
Void putdata();
Cout <<a<<b;
};
Int main()
Demoaa;
aa.putdata;
return 0;
it is a type of constructor which name is similar to the class name, which is automatically invobed the
constructor which has no aurgument is called default constructor.
Parameter constructor.
a constructor is a special name function name as the class name and which is automatically
Code;
Class demo
Int a, b;
Public ::
A=m;
B=n;
Void putdata();
Cout<<A<<b;
};
Int main;
Copy constructor;
When we need to initialize the variable with the value of variable with another variable same type
then we use concept of copy constructor.
Code:
class demo
Int a;
Public:
Demo()
{
a=10;
Demo(demo & b)