Domanda

Constructors:

A()
{
    std::cout<<"In A const";
}

A(int a = 3)
{
    std::cout<<"In a with default :"<<a;
}

Creating objects:

A a;
A a1(4);

The above code is showing error: call of overloaded 'A()' is ambiguous

È stato utile?

Soluzione

You've given a default value to the second constructor:

A(int a = 3)

So this covers both instances of: A() and A(3), making the first definition redundant

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top