Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Default Value Parameters (1 array, 1 Default)

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.6k Views
  • 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 Offline
    T Offline
    Thugzook
    wrote on 8 May 2015, 20:49 last edited by Thugzook 5 Dec 2015, 20:30
    #1

    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
    0
    • M Offline
      M Offline
      mcosta
      wrote on 8 May 2015, 20:56 last edited by
      #2

      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
      1
      • T Offline
        T Offline
        Thugzook
        wrote on 12 May 2015, 20:31 last edited by
        #3

        Thank you.

        1 Reply Last reply
        0

        1/3

        8 May 2015, 20:49

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved