Operator Overloading and Callable Classes
operator + and call() make types behave like numbers or functions.
Example
class V {
final int x, y;
V(this.x, this.y);
V operator +(V o) => V(x + o.x, y + o.y);
int call() => x * y;
}
void main() {
var v = V(1, 2) + V(3, 4);
print("${v.x} ${v.y} ${v()}");
}Exercise
Overload plus.
V operator (V o)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.