// Delegating ctors are different than in Java. // Granted, this problem would be better solved by using default arguments. #include class Ratio { public: Ratio(int a, int b) : numerator(a), denominator(b) { if (b==0) throw "Can’t divide by zero!"; // Should really reduce the fraction to lowest terms, here. } Ratio() { Ratio(1,1); // Set default values 😈 } double value() const { return numerator / (denominator+0.0); } private: int numerator, denominator; friend std::ostream & operator<<(std::ostream &, const Ratio &); }; std::ostream & operator<<(std::ostream &out, const Ratio &r) { return out << r.numerator << '/' << r.denominator; } using namespace std; int main() { Ratio r(012,345); cout << r << " = " << r.value() << '\n'; Ratio q; // Should be 1/1 cout << q << " = " << q.value() << '\n'; return 0; }