Default Constructor in C++

A constructor that accept no parameter is called the default constructor. The default constructor for class A is A :: A( ). If no such constructor is defined, then the compiler supplies a default constructor.

A default constructor is one which can be called with no arguments. Most commonly, a default constructor is declared without any parameters, but it is also possible for a constructor with parameters to be a default constructor if all of those parameters are given default values.

Example:

class abc
{
private:
    char nm[];
public:
    abc ( )
    {
       cout<<”enter your name:”;
       cin>>nm;
    }
    void display( )
    {
       cout<<nm;
    }
};
int main( )
{
    clrscr( );
    abc d;
    d.display( );
    getch( );
return(0);
}

Related posts