Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    3
    1956
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      Thugzook last edited by Thugzook

      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);
      1 Reply Last reply Reply Quote 0
      • M
        mcosta 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)
        {
        ...
        }
        

        Once your problem is solved don't forget to:

        • Mark the thread as SOLVED using the Topic Tool menu
        • Vote up the answer(s) that helped you to solve the issue

        You can embed images using (http://imgur.com/) or (http://postimage.org/)

        1 Reply Last reply Reply Quote 1
        • T
          Thugzook last edited by

          Thank you.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post