C++ overloading limits: which of the following functions cannot be overloaded? (Choose the only correct option.)

Difficulty: Easy

Correct Answer: The function main

Explanation:


Introduction / Context:
Function overloading in C++ permits multiple functions with the same name to co-exist in the same scope as long as their parameter lists differ. However, not every function name in a program is eligible for overloading. Recognizing the exceptions prevents invalid API designs and linker conflicts.


Given Data / Assumptions:

  • Overloading is distinguished strictly by the parameter list (not return type alone).
  • We consider free functions and class member functions of various kinds.
  • We must identify the one that the language forbids to overload.


Concept / Approach:

The program entry point main has a unique, implementation-defined signature (commonly int main() or int main(int, char**)) and cannot be overloaded. By contrast, ordinary member functions (including static and virtual) may be overloaded within their class scope by providing different parameter lists. Note that “virtual” concerns overriding across a hierarchy, which is orthogonal to overloading within the same scope.


Step-by-Step Solution:

List candidates: main, non-static member, static member, virtual member. Recall the special rule: main must be unique → cannot be overloaded. Confirm the rest: all can be overloaded by varying parameter lists. Select “The function main.”


Verification / Alternative check:

Attempt to provide two main definitions with different parameters; the program is ill-formed. In a class, define several functions with the same name but different parameters (static or non-static, virtual or not) and they overload successfully in that class scope.


Why Other Options Are Wrong:

Non-static, static, and virtual members may all be overloaded (overriding is a different concept for virtuals).


Common Pitfalls:

  • Confusing overloading (same scope, different signatures) with overriding (derived class replaces a virtual function).
  • Expecting return type differences alone to create overloads; they do not.


Final Answer:

The function main

Discussion & Comments

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