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

Info iconThis 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
Background image of page 1

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

View Full DocumentRight 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.
Background 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.
Background image of page 3

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

View Full DocumentRight 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
Background 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 float f; fun(f); // matches void fun(double)
Background image of page 5

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

View Full DocumentRight Arrow Icon
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. template <class T>
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/10/2011 for the course ENEL 409 taught by Professor Moussavi during the Fall '11 term at University of Calgary.

Page1 / 26

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

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online