lecture23 Function Overloading

lecture23 Function Overloading - 1 © Janice Regan CMPT 128...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 © Janice Regan, CMPT 128, February. 2007 CMPT 128: Introduction to Computing Science for Engineering Students Function overloading © Janice Regan, CMPT 128, February 2007 2 Parameters and Arguments Terms are often used interchangeably Formal parameters In function declaration and function definition Arguments or actual parameters Variables used as values of formal parameters in function calls (argument lists) Should be declared to have the correct type (the same type as the formal parameter the variable replaces) in the calling program © Janice Regan, CMPT 128, February 2007 3 Mixed Parameter Lists Can combine passing mechanisms Parameter lists can include pass-by-value and pass-by-reference parameters Order of arguments in list is critical: void mixedCall(int& par1, int par2, double* par3); Function call: mixedCall(arg1, arg2, arg3); arg1 must be integer type, is passed by reference, its value can be changed within the function arg2 must be integer type, is passed by value arg3 must be pointer to double type, pointer passed by value, variable it points to can be modified © Janice Regan, CMPT 128, February 2007 4 Arrays in Mixed Parameter Lists Can combine passing mechanisms For arrays remember the identifier of the array is a pointer to the array (automatically passed by reference) What if we want to pass an array into a function but we do not want the function to be able to modify the contents of the array? This is another important use of the const keyword © Janice Regan, CMPT 128, February 2007 5 Arrays in Mixed Parameter Lists What if we want to pass an array into a function but we do not want the function to be able to modify the contents of the array? void mixedCall(int& par1, const int par2 [ ]); Function call: mixedCall(arg1, arg2); arg1 must be integer type, it is passed by reference, its value can be changed within the called function arg2 is of type constant integer array, arg2 is the identifier of an integer array in your calling program, By making the formal argument of your function a constant integer array you are assuring that your function mixedCall cannot modify the contents of the array arg2 © Janice Regan, CMPT 128, February 2007...
View Full Document

{[ snackBarMessage ]}

Page1 / 22

lecture23 Function Overloading - 1 © Janice Regan CMPT 128...

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

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