Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constructor default parameter [duplicate]

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

like image 666
Shreyas Avatar asked Feb 20 '26 15:02

Shreyas


1 Answers

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

like image 110
CodingIntrigue Avatar answered Feb 22 '26 06:02

CodingIntrigue



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!