Can we say that "C language operators are polymorphic"开发者_Go百科 ? For example if
int a, b;
float p, q;
a+b;
a+p;
p+q;
etc will generate different code when assembled, as the type conversion is needed the floating point coprocessor instruction needs to be executed to make the conversion and the floating point additions. So the operators operate differently depending on the objects they act upon.
Although these are implicit so if this can theoretically be called static polymorphism, operator overloading?
Yes, in theory this could be called static polymorphism or operator overloading. But since the polymorphism is fixed in its range of applicable types by the language definition, it's not a very interesting polymorphism.
If we consider the operator +
a function, then it matches the definition of a polymorphic function because it can "evaluate to or be applied to values of different types". So yes, it's a polymorphic function.
精彩评论