{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

set08 - Other Features of C Functions Overloading Functions...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Other Features of C++ Functions Other Features of C++ Functions Overloading Functions Default Function Arguments Template Functions
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Last modified: Jan. 2001 1998 Dr. M. Moussavi 2 C++ functions - default arguments C++ functions - default arguments A function argument may have a default value. char fun (int h = 24, int w = 80, char ch = ‘ ‘); fun(); fun(2); fun(2, 8); fun(2, 8, ‘B’); The right most not initialized argument must be supplied with a default initializer before any argument to its left may be supplied. You should initialize arguments either at the function prototype or function definition, not both.
Image of page 2
Last modified: Jan. 2001 1998 Dr. M. Moussavi 3 Function overloading Function overloading Function names overloading allows multiple function instances that provide a common operation on different arguments to share a common name: int fun(void); int fun(int); int fun (int , int); void fun (int, double); Function with same name and different signature in the same scope are called overloaded functions.
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Last modified: Jan. 2001 1998 Dr. M. Moussavi 4 Function overloading Function overloading There are three possible outcome of a call of an overloaded function: Exact match No match Ambiguous match The process of finding a match among overloaded functions can happen through (Detail of this will not be discussed in this course): Exact match match by promotion match by standard conversion
Image of page 4
Last modified: Jan. 2001 1998 Dr. M. Moussavi 5 Function overloading Function overloading Examples: void fun(int) void fun(double); void fun(char*); void fun(void*); long n; fun(n); // ambiguous fun(&n) // matches void fun(void*) float f; fun(f); // matches void fun(double)
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Last modified: Jan. 2001 1998 Dr. M. Moussavi 6 C++ functions - template functions C++ functions - template functions definition definition Template function is a generic function that can be instantiated for different signatures.
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern