▲ | HarHarVeryFunny 4 days ago | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> In C++ this can be done when very verbose inheritance and virtual calls. No - in C++ you'd just define the operators (either as global functions, or member functions of the types/classes in question), and the language's overload resolution rules would select the right implementation for each usage. You could use inheritence (and virtual overrides if needed), or templates/generics, if you wanted to - C++ certainly gives you a lot of ways to make things more complex and shoot yourself in the foot, but the normal/obvious way would just be to define the overloaded operators and be done with it. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | layer8 4 days ago | parent [-] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The expression problem is about dynamic dispatch, not static dispatch. For example, you call a function F that returns an object of one of the relevant types, and another function G that returns one of the relevant operations, and then you apply the operation to the object. How can you have F extend the set of types, and also G extend the set of operations, without having to recompile the caller, or without F and G having to coordinate, and also avoid a runtime error due to a missing implementation of some operation for some type. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|