[SOLVED] Default Value Parameters (1 array, 1 Default)



  • 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);


  • 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)
    {
    ...
    }
    


  • Thank you.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.