开发者

Can we say that "C language operators are polymorphic"?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜