3 ms·
The alternative GP is advocating for is "none of the above." Meaning "operators are only defined for primitive types" which is perfectly fine when working with
by duped 3y ago
The alternative GP is advocating for is "none of the above." Meaning "operators are only defined for primitive types" which is perfectly fine when working with C.
If you wanted to use an abstraction over non primitive types for such things you would use a normal function.
- c-cube 3y agoBut then you make built-in types special. One of the tenets of C++ is that user defined types have as much power as built-in types.
- duped 3y agoBuilt in types are special. The compiler needs to define operator precedence and certain semantics (commutativity, associativity, overflow, etc) that cannot be expressed in the type system or enforced by the interface. The fact that it makes syntax "nicer" for user defined types is at best subjective and at worst an anti-pattern because it leads to bad compiled code and confused programmers. Function calls are unambiguous and follow the same rules as other function calls, while operator overloading does not.