samedi 3 avril 2021

error while creating object with no arguments using parameterized constructor with default arguments

I have created a parameterized constructor with default arguments as follows:

Rectangle(int l=2,int b=2)
{
    setLength(l);
    setBreadth(b);
}

When I'm creating object like

Rectangle r; 

It is taking both default arguments.

When

Rectangle r(10);

It takes another default argument.

But when

Rectangle r();

It's not working and throws and error,rather than taking both the default arguments.

Aucun commentaire:

Enregistrer un commentaire