dimanche 31 juillet 2016

How many constructors are defined for a class?

So I'm preparing for an upcoming C++ exam and came across this question about classes and constructors: "How many constructors does the class Fraction have?"

class Fraction {
//...
public:
   Fraction(int numerator = 0, int denominator = 1);
//...
}

I thought it's only one, but they suggested there are 3:

Fraction();
Fraction(n);
Fraction(n, d);

Or in other words: Is a function with default values an overloaded function?

Aucun commentaire:

Enregistrer un commentaire