Code:
For example
class Box
{
int l,w,h;
public:
Box() // constructor
{
l=10;
h=20;
w=30;
}
}
main()
{
Box b1;
}
This is an simple example of constructor which is shown as above. In this an object is initialized and how it is created is shown. You will find that the box named constructor is created in the program. The name of the constructor and the class should be similar which is also shown. After initialization the value of objects are also assigned in the program. This is the most simplest and easiest program of constructor in C++.
Bookmarks