Oop stackexchange

https://softwareengineering.stackexchange.com/questions/316507/what-is-the-correct-oop-relation-between-complex-and-real-numbers


 * @KevinMills math is very different from programming here in the sense that math objects are immutable. In the context of programming, establishing relation between real and complex numbers would be rather "a category error or category mistake" as was pointed in this answer to similar (possibly diplicate) question – gnat Apr 22 '16 at 12:16

https://softwareengineering.stackexchange.com/questions/199331/is-there-a-specific-name-for-the-square-inherits-from-rectangle-paradox/238420#238420


 * Unfortunately, it is difficult to model the relationships between numeric types using the typical feature set of an object oriented language. You can get close by modelling both real and complex as instances of an interface" number", but OO semantics will trip you up because in many cases functions of real values will want to return real and the same functions will want to return complex for complex arguments. You'll have to compromise and just return numbers without specifying which, but that ends up with a loss of type information (at least for static languages), which may be undesirable. A better answer is the use of polymorphic functions, rather than classes, along with some kindof constraint system to ensure your type arguments are proper numeric types. This is the way many functional languages handle the problem, and if c++ ever gets the template concept constraint system the c++ committee have been working on for years, you'd be able to achieve a similar result in c++. Otherwise, ad-hoc overloading is probably the best that can be achieved.

https://en.cppreference.com/w/cpp/language/constraints

links
Category mistake