In type theory terms, what kind of polymorphism does function overloading in C++ exemplify? Pick the standard category used to describe overloading.

Difficulty: Easy

Correct Answer: Ad-hoc polymorphism

Explanation:


Introduction:
Polymorphism comes in several flavors, and C++ supports more than one. This question asks you to classify function overloading using the conventional terminology from type theory and programming languages.


Given Data / Assumptions:

  • Multiple functions share the same name.
  • They differ by parameter types or arity.
  • Binding occurs at compile time via overload resolution.


Concept / Approach:
Function overloading is a form of ad-hoc polymorphism. The compiler chooses among distinct implementations based on the static types of the arguments. This differs from parametric polymorphism (templates/generics) and from subtype (runtime) polymorphism (virtual functions). In C++, overloading and operator overloading are resolved at compile time without a vtable lookup.


Step-by-Step Solution:
1) Present an overload set, e.g., f(int) and f(double).2) Call f with different argument types; the compiler selects the best match.3) Note that each overload is a separate function body (ad-hoc).4) Conclude the classification: ad-hoc polymorphism.


Verification / Alternative check:
Inspect the generated symbols; you will see distinct mangled names for each overload, confirming there are separate implementations.


Why Other Options Are Wrong:
Virtual polymorphism: refers to runtime (subtype) polymorphism via virtual dispatch.Transient / Pseudo polymorphism: non-standard or informal terms not used to classify overloading.


Common Pitfalls:
Confusing templates (parametric) with overloading (ad-hoc). Templates generate implementations from a single pattern; overloading selects among multiple concrete functions.


Final Answer:
Ad-hoc polymorphism

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion