Default constructor in C++ programming is a constructor which has no parameters. The default constructor will be called at the time of creating object of that class.
#include<iostream.h>
#include<conio.h>
class cls //'cls' is name of Class.
{
public:
cls() //this is default constructor.
{
cout<<"This is Default Constructor"<<endl;
}
void fun() //this is function.
{
cout<<"This is Simple Function";
}
};
void main()
{ //'obj' is object of Class 'cls' and calling
cls obj; //default constructor.
obj.fun(); //calling 'fun()' function.
getch();
}
#include<iostream.h>
#include<conio.h>
class cls
{
public:
cls() //this is Constructor.
{
cout<<"Constructor Called"<<endl;
}
~cls() //this is Destructor.
{
cout<<"Destructor Called"<<endl;
getch();
}
};
void main()
{
cls obj; //'obj' is object of class 'cls'.
getch();
}