How many constructors does the class have?

There is only one constructor corresponding to the posted declaration, not three overloads.

The calls

Fraction();
Fraction(n);

are equivalent to:

Fraction(0, 1);
Fraction(n, 1);

One more way to convince yourself that there is only one constructor corresponding to the declaration is that you only need to define one constructor, not three.

The section of the C++11 standard on default arguments has this:

8.3.6 Default arguments

1 If an initializer-clause is specified in a parameter-declaration this initializer-clause is used as a default argument. Default arguments will be used in calls where trailing arguments are missing.

2 [ Example: the declaration

void point(int = 3, int = 4);

declares a function that can be called with zero, one, or two arguments of\ type int. It can be called in any of these ways:

point(1,2); point(1); point();

The last two calls are equivalent to point(1,4) and point(3,4), respectively. —end example ]

Now the main question.

How many constructors does the class Fraction have?

If the person that framed the question wants to include the move constructor and the copy constructor, which are implicitly generated by the compiler unless explicitly deleted, in the set of constructors, then the answer is three. In that case, the question is a trick question.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)