[SOLVED] Default Value Parameters (1 array, 1 Default)
-
wrote on 8 May 2015, 20:49 last edited by Thugzook 5 Dec 2015, 20:30
Hello.
For my computer Science teacher, he required us to have a function with a default value; however, I'm running into difficulties when I attempt to pass an array into this function.
Currently:
the .cpp
int valChars[TOT_CHARS]; ///call randNum(int *) to fill the int array randNum(valChars);
the function in question
void MainGame2::randNum (int valChars[],int TOT_CHARS = 7)
the header
void randNum (int valChars[] , int TOT_CHARS);
-
wrote on 8 May 2015, 20:56 last edited by
Hi,
in C++ you have to declare the argument default value in the function declaration (in the .h file)
// MainGame2.h class MainMage2 { ... void randNum(int valChars[], int TOT_CHARS = 7); };
// MainGame.cpp void MainGame2::randNum(int valChars[], int TOT_CHARS) { ... }
-
wrote on 12 May 2015, 20:31 last edited by
Thank you.
1/3