Margaret Rouse is an award-winning technical writer and teacher known for her ability to explain complex technical subjects simply to a non-technical, business audience. Over…
Ad hoc polymorphism refers to polymorphic functions that can be applied to different argument types known by the same name in a programming language. Ad hoc polymorphism is also known as function overloading or operator overloading because a polymorphic function can represent a number of unique and potentially heterogeneous implementations depending on the type of argument it is applied to.
Ad hoc polymorphism defines operators that can be used for different argument types. It follows a dispatch mechanism in which the control moving from one named function is dispatched to several other functions without specifying the function being called. This function overloading permits multiple functions taking different argument types to be known by the same name as the compiler and interpreter calls the right function. For example in the following code:
int a, b;
float x, y;
printf(“%d %f”, a+b, x+y);
The symbol ‘+’ is used in two different ways. In the expression a+b, it stands for the function that adds two integers. In the expression x+y, it stands for the function that adds two floats. Thus, ad hoc polymorphism refers to the use of a single function name to indicate two or more unique functions. The compiler decides which function to call depending on the type of arguments.
Ad hoc polymorphism is supported by almost all programming languages for built-in operations such as ‘+’, ‘-‘, ‘*’, etc.
Techopedia’s editorial policy is centered on delivering thoroughly researched, accurate, and unbiased content. We uphold strict sourcing standards, and each page undergoes diligent review by our team of top technology experts and seasoned editors. This process ensures the integrity, relevance, and value of our content for our readers.
Margaret is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages.
What is AI Ethics? The field of AI ethics is about the rules and values guiding how artificial intelligence (AI)...
Maria WebbTechnology journalist
What is AI TRiSM? AI TRiSM (Trust, Risk, and Security Management) is a market segment for AI governance products and...
Margaret RouseTechnology Expert
What is Know Your Customer (KYC)? Know Your Customer (KYC) is the process that financial institutions such as banks use...
Nicole WillingTechnology Journalist
Trending NewsLatest GuidesReviewsTerm of the Day