Robert wants to write a function that can either accept two parameters or three. What feature of C++ should he use to achieve this?

  • Function Overloading
  • Function Pointers
  • Function Templates
  • Inheritance
Robert should use Function Overloading in C++ to write a function that can accept either two or three parameters. Function Overloading allows a programmer to define multiple functions with the same name but different parameter lists. When Robert calls the function with two parameters, one version of the function is invoked; when he calls it with three parameters, a different version is invoked, providing flexibility and reusability in his code.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *