Christopher Peterson
Christopher Peterson

Reputation: 1027

C++ Constructor Question

If I create a default parameter in my ctor then how will the compiler know which ctor to call the default ctor or the ctor with a default parameter.

Upvotes: 0

Views: 68

Answers (1)

James McNellis
James McNellis

Reputation: 355059

It won't. If you have the following class:

struct S {
    S();
    S(int = 0);
};

Then the compiler will report that the following is ambiguous:

S x;

Upvotes: 6

Related Questions