operator [] method
Access numerator or denominator via index. In particular, ´0´ refers to the numerator while ´1´ to the denominator.
Throws if index
is not 0
or 1
.
Implementation
int operator [](int index) {
if (index == 0) {
return numerator;
}
if (index == 1) {
return denominator;
}
throw FractionException(
'The index you gave ($index) is not valid: it must be either 0 or 1.',
);
}