I find it difficult to understand the topic of operator overloading in C ++ and Java.
For example, I define a new Fraction class:
class Fraction {
public:
Fraction (int top, int bottom) { t = top; b = bottom; }
int numerator() { return t; }
int denominator() { return b; }
private:
int t, b;
};
and I want to overload the operator <<to print Fraction. How am i doing this? Do I need to overload it inside a class fraction or outside a class fraction?
In java - is it possible to overload a statement? How can I do this (for example, I want to overload the statement +).
If there is a metric in this question, it will be great.
source
share