Ad Hoc Polymorphism: Function Overloading

 < Day Day Up > 



Ad hoc polymorphism is function overloading. When you declare and define several versions of a function the function name remains the same but the function signature changes, meaning the number of function parameters and the types of those parameters varies from one version of the overloaded function to another. The decision regarding which version of the function to call is made by the compiler at compile time using the number and types of arguments passed in the function call. If the compiler finds a function matching the signature of the function call then it uses that version of the function. Failure to find a match results in a compiler error.

Operator overloading is function overloading and therefore works the same way. If an operator is applied to a user-defined type object, and that operator is overloaded to work in the context of that particular user-defined type, then the overloaded version of the operator is used. Failure on the part of the compiler to find an overloaded version of the operator results in a compiler error.



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net