Change only a specific Default Parameter on a function2019 Community Moderator ElectionUse of 'const' for function parametersUse 'class' or 'typename' for template parameters?Why can templates only be implemented in the header file?Why do we need virtual functions in C++?Where to put default parameter value in C++?Why does changing 0.1f to 0 slow down performance by 10x?QInputDialog Parameter DefaultsAre the days of passing const std::string & as a parameter over?Qt: How to call a set to a toString, return in get function and testing a boolCan`t overload the operator << for a my own class

Why do phishing e-mails use faked e-mail addresses instead of the real one?

I've given my players a lot of magic items. Is it reasonable for me to give them harder encounters?

An Undercover Army

Can you run a ground wire from stove directly to ground pole in the ground

Should we avoid writing fiction about historical events without extensive research?

What is a term for a function that when called repeatedly, has the same effect as calling once?

Is every open circuit a capacitor?

Using the imperfect indicative vs. subjunctive with si

Does the in-code argument passing conventions used on PDP-11's have a name?

Why can't we use freedom of speech and expression to incite people to rebel against government in India?

Can a Mexican citizen living in US under DACA drive to Canada?

Paper published similar to PhD thesis

Is "cogitate" an appropriate word for this?

Are there other characters in the Star Wars universe who had damaged bodies and needed to wear an outfit like Darth Vader?

New invention compresses matter to produce energy? or other items? (Short Story)

What's the best tool for cutting holes into duct work?

Computing the volume of a simplex-like object with constraints

Quitting employee has privileged access to critical information

How do we objectively assess if a dialogue sounds unnatural or cringy?

School performs periodic password audits. Is my password compromised?

Why aren't there more gauls like Obelix?

Where do you go through passport control when transiting through another Schengen airport on your way out of the Schengen area?

Replacing tantalum capacitor with ceramic capacitor for Op Amps

The (Easy) Road to Code



Change only a specific Default Parameter on a function



2019 Community Moderator ElectionUse of 'const' for function parametersUse 'class' or 'typename' for template parameters?Why can templates only be implemented in the header file?Why do we need virtual functions in C++?Where to put default parameter value in C++?Why does changing 0.1f to 0 slow down performance by 10x?QInputDialog Parameter DefaultsAre the days of passing const std::string & as a parameter over?Qt: How to call a set to a toString, return in get function and testing a boolCan`t overload the operator << for a my own class










10















I'm using qt and I am trying to use the QInputDialog::getText() function to get input from the user, from the Documentation the definition of the function is:



QString QInputDialog::getText(QWidget * parent, const QString & title, const QString & label, QLineEdit::EchoMode mode = QLineEdit::Normal, const QString & text = QString(), bool * ok = 0, Qt::WindowFlags flags = 0, Qt::InputMethodHints inputMethodHints = Qt::ImhNone)


and here is my code:



bool ok=0;
newAddress = QInputDialog::getText(0,"Enter an Address to Validate",
"Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)"
,&ok);


but I get the Error:



error: no matching function for call to 'QInputDialog::getText(int, const char [29], const char [80], bool*)'
,&ok);
^


but when I pass in all the arguments before the *ok argument like:



bool ok=0;
newAddress = QInputDialog::getText(0,"Enter an Address to Validate",
"Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)"
,QLineEdit::Normal,
QString(),&ok);


it works.



I really don't understand why cant I just change the default parameter I want and leave the rest as default?.










share|improve this question




























    10















    I'm using qt and I am trying to use the QInputDialog::getText() function to get input from the user, from the Documentation the definition of the function is:



    QString QInputDialog::getText(QWidget * parent, const QString & title, const QString & label, QLineEdit::EchoMode mode = QLineEdit::Normal, const QString & text = QString(), bool * ok = 0, Qt::WindowFlags flags = 0, Qt::InputMethodHints inputMethodHints = Qt::ImhNone)


    and here is my code:



    bool ok=0;
    newAddress = QInputDialog::getText(0,"Enter an Address to Validate",
    "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)"
    ,&ok);


    but I get the Error:



    error: no matching function for call to 'QInputDialog::getText(int, const char [29], const char [80], bool*)'
    ,&ok);
    ^


    but when I pass in all the arguments before the *ok argument like:



    bool ok=0;
    newAddress = QInputDialog::getText(0,"Enter an Address to Validate",
    "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)"
    ,QLineEdit::Normal,
    QString(),&ok);


    it works.



    I really don't understand why cant I just change the default parameter I want and leave the rest as default?.










    share|improve this question


























      10












      10








      10








      I'm using qt and I am trying to use the QInputDialog::getText() function to get input from the user, from the Documentation the definition of the function is:



      QString QInputDialog::getText(QWidget * parent, const QString & title, const QString & label, QLineEdit::EchoMode mode = QLineEdit::Normal, const QString & text = QString(), bool * ok = 0, Qt::WindowFlags flags = 0, Qt::InputMethodHints inputMethodHints = Qt::ImhNone)


      and here is my code:



      bool ok=0;
      newAddress = QInputDialog::getText(0,"Enter an Address to Validate",
      "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)"
      ,&ok);


      but I get the Error:



      error: no matching function for call to 'QInputDialog::getText(int, const char [29], const char [80], bool*)'
      ,&ok);
      ^


      but when I pass in all the arguments before the *ok argument like:



      bool ok=0;
      newAddress = QInputDialog::getText(0,"Enter an Address to Validate",
      "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)"
      ,QLineEdit::Normal,
      QString(),&ok);


      it works.



      I really don't understand why cant I just change the default parameter I want and leave the rest as default?.










      share|improve this question
















      I'm using qt and I am trying to use the QInputDialog::getText() function to get input from the user, from the Documentation the definition of the function is:



      QString QInputDialog::getText(QWidget * parent, const QString & title, const QString & label, QLineEdit::EchoMode mode = QLineEdit::Normal, const QString & text = QString(), bool * ok = 0, Qt::WindowFlags flags = 0, Qt::InputMethodHints inputMethodHints = Qt::ImhNone)


      and here is my code:



      bool ok=0;
      newAddress = QInputDialog::getText(0,"Enter an Address to Validate",
      "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)"
      ,&ok);


      but I get the Error:



      error: no matching function for call to 'QInputDialog::getText(int, const char [29], const char [80], bool*)'
      ,&ok);
      ^


      but when I pass in all the arguments before the *ok argument like:



      bool ok=0;
      newAddress = QInputDialog::getText(0,"Enter an Address to Validate",
      "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)"
      ,QLineEdit::Normal,
      QString(),&ok);


      it works.



      I really don't understand why cant I just change the default parameter I want and leave the rest as default?.







      c++ qt qt5






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday







      Makhele Sabata

















      asked yesterday









      Makhele SabataMakhele Sabata

      9417




      9417






















          3 Answers
          3






          active

          oldest

          votes


















          13














          When you pass a value for a particular parameter that has a default argument, you have to pass values for all the default parameters before it. Otherwise, the value you have passed will be taken as the value for the first default parameter.



          So you have to do this:



          newAddress = QInputDialog::getText(
          0,
          "Enter an Address to Validate",
          "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)",
          QLineEdit::Normal,
          QString(),
          &ok);


          You can leave out passing values for the parameters after bool * parameter.



          The C++ standard states in [dcl.fct.default]/1




          Default arguments will be used in calls where trailing arguments are missing.







          share|improve this answer

























          • I worked with Python when i started learning programming, and it i had this functionality where you could pass the arguments by name. it would be nice if they had something like that in C++. Thanks for the answer I wasn't aware of the trailing arguments issue.

            – Makhele Sabata
            yesterday












          • You are welcome.

            – P.W
            yesterday


















          7














          In C++ you can only use (one or multiple) default parameters at the end of the parameter list. If you omit parameters in the middle, the compiler has no way of knowing, which argument belongs to which parameter. Therefore you have to specify the default parameters QLineEdit::Normal and QString() manually before passing &ok.



          In your not working case the compiler tries to match your bool pointer to the next type in the parameter list, which is QLineEdit::EchoMode and therefore not compatible.






          share|improve this answer






























            2














            the error is beacuse of the optional paramteres:



            QString QInputDialog::getText(
            QWidget * parent,
            const QString & title,
            const QString & label,
            QLineEdit::EchoMode mode = QLineEdit::Normal,
            const QString& text = QString(),
            bool * ok = 0,
            Qt::WindowFlags flags = 0,
            Qt::InputMethodHints inputMethodHints = Qt::ImhNone)


            QInputDialog::getText(
            0,
            "Enter an Address to Validate",
            "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)",
            --> QLineEdit::EchoMode ??
            --> QString& text ??
            &ok);


            if you set one optional parameter, you have to set all the optional paramteters to the left of that, in your case QLineEdit::EchoMode and QString& text






            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55020088%2fchange-only-a-specific-default-parameter-on-a-function%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              13














              When you pass a value for a particular parameter that has a default argument, you have to pass values for all the default parameters before it. Otherwise, the value you have passed will be taken as the value for the first default parameter.



              So you have to do this:



              newAddress = QInputDialog::getText(
              0,
              "Enter an Address to Validate",
              "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)",
              QLineEdit::Normal,
              QString(),
              &ok);


              You can leave out passing values for the parameters after bool * parameter.



              The C++ standard states in [dcl.fct.default]/1




              Default arguments will be used in calls where trailing arguments are missing.







              share|improve this answer

























              • I worked with Python when i started learning programming, and it i had this functionality where you could pass the arguments by name. it would be nice if they had something like that in C++. Thanks for the answer I wasn't aware of the trailing arguments issue.

                – Makhele Sabata
                yesterday












              • You are welcome.

                – P.W
                yesterday















              13














              When you pass a value for a particular parameter that has a default argument, you have to pass values for all the default parameters before it. Otherwise, the value you have passed will be taken as the value for the first default parameter.



              So you have to do this:



              newAddress = QInputDialog::getText(
              0,
              "Enter an Address to Validate",
              "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)",
              QLineEdit::Normal,
              QString(),
              &ok);


              You can leave out passing values for the parameters after bool * parameter.



              The C++ standard states in [dcl.fct.default]/1




              Default arguments will be used in calls where trailing arguments are missing.







              share|improve this answer

























              • I worked with Python when i started learning programming, and it i had this functionality where you could pass the arguments by name. it would be nice if they had something like that in C++. Thanks for the answer I wasn't aware of the trailing arguments issue.

                – Makhele Sabata
                yesterday












              • You are welcome.

                – P.W
                yesterday













              13












              13








              13







              When you pass a value for a particular parameter that has a default argument, you have to pass values for all the default parameters before it. Otherwise, the value you have passed will be taken as the value for the first default parameter.



              So you have to do this:



              newAddress = QInputDialog::getText(
              0,
              "Enter an Address to Validate",
              "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)",
              QLineEdit::Normal,
              QString(),
              &ok);


              You can leave out passing values for the parameters after bool * parameter.



              The C++ standard states in [dcl.fct.default]/1




              Default arguments will be used in calls where trailing arguments are missing.







              share|improve this answer















              When you pass a value for a particular parameter that has a default argument, you have to pass values for all the default parameters before it. Otherwise, the value you have passed will be taken as the value for the first default parameter.



              So you have to do this:



              newAddress = QInputDialog::getText(
              0,
              "Enter an Address to Validate",
              "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)",
              QLineEdit::Normal,
              QString(),
              &ok);


              You can leave out passing values for the parameters after bool * parameter.



              The C++ standard states in [dcl.fct.default]/1




              Default arguments will be used in calls where trailing arguments are missing.








              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited yesterday

























              answered yesterday









              P.WP.W

              16.1k31455




              16.1k31455












              • I worked with Python when i started learning programming, and it i had this functionality where you could pass the arguments by name. it would be nice if they had something like that in C++. Thanks for the answer I wasn't aware of the trailing arguments issue.

                – Makhele Sabata
                yesterday












              • You are welcome.

                – P.W
                yesterday

















              • I worked with Python when i started learning programming, and it i had this functionality where you could pass the arguments by name. it would be nice if they had something like that in C++. Thanks for the answer I wasn't aware of the trailing arguments issue.

                – Makhele Sabata
                yesterday












              • You are welcome.

                – P.W
                yesterday
















              I worked with Python when i started learning programming, and it i had this functionality where you could pass the arguments by name. it would be nice if they had something like that in C++. Thanks for the answer I wasn't aware of the trailing arguments issue.

              – Makhele Sabata
              yesterday






              I worked with Python when i started learning programming, and it i had this functionality where you could pass the arguments by name. it would be nice if they had something like that in C++. Thanks for the answer I wasn't aware of the trailing arguments issue.

              – Makhele Sabata
              yesterday














              You are welcome.

              – P.W
              yesterday





              You are welcome.

              – P.W
              yesterday













              7














              In C++ you can only use (one or multiple) default parameters at the end of the parameter list. If you omit parameters in the middle, the compiler has no way of knowing, which argument belongs to which parameter. Therefore you have to specify the default parameters QLineEdit::Normal and QString() manually before passing &ok.



              In your not working case the compiler tries to match your bool pointer to the next type in the parameter list, which is QLineEdit::EchoMode and therefore not compatible.






              share|improve this answer



























                7














                In C++ you can only use (one or multiple) default parameters at the end of the parameter list. If you omit parameters in the middle, the compiler has no way of knowing, which argument belongs to which parameter. Therefore you have to specify the default parameters QLineEdit::Normal and QString() manually before passing &ok.



                In your not working case the compiler tries to match your bool pointer to the next type in the parameter list, which is QLineEdit::EchoMode and therefore not compatible.






                share|improve this answer

























                  7












                  7








                  7







                  In C++ you can only use (one or multiple) default parameters at the end of the parameter list. If you omit parameters in the middle, the compiler has no way of knowing, which argument belongs to which parameter. Therefore you have to specify the default parameters QLineEdit::Normal and QString() manually before passing &ok.



                  In your not working case the compiler tries to match your bool pointer to the next type in the parameter list, which is QLineEdit::EchoMode and therefore not compatible.






                  share|improve this answer













                  In C++ you can only use (one or multiple) default parameters at the end of the parameter list. If you omit parameters in the middle, the compiler has no way of knowing, which argument belongs to which parameter. Therefore you have to specify the default parameters QLineEdit::Normal and QString() manually before passing &ok.



                  In your not working case the compiler tries to match your bool pointer to the next type in the parameter list, which is QLineEdit::EchoMode and therefore not compatible.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  AlbertMAlbertM

                  352210




                  352210





















                      2














                      the error is beacuse of the optional paramteres:



                      QString QInputDialog::getText(
                      QWidget * parent,
                      const QString & title,
                      const QString & label,
                      QLineEdit::EchoMode mode = QLineEdit::Normal,
                      const QString& text = QString(),
                      bool * ok = 0,
                      Qt::WindowFlags flags = 0,
                      Qt::InputMethodHints inputMethodHints = Qt::ImhNone)


                      QInputDialog::getText(
                      0,
                      "Enter an Address to Validate",
                      "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)",
                      --> QLineEdit::EchoMode ??
                      --> QString& text ??
                      &ok);


                      if you set one optional parameter, you have to set all the optional paramteters to the left of that, in your case QLineEdit::EchoMode and QString& text






                      share|improve this answer



























                        2














                        the error is beacuse of the optional paramteres:



                        QString QInputDialog::getText(
                        QWidget * parent,
                        const QString & title,
                        const QString & label,
                        QLineEdit::EchoMode mode = QLineEdit::Normal,
                        const QString& text = QString(),
                        bool * ok = 0,
                        Qt::WindowFlags flags = 0,
                        Qt::InputMethodHints inputMethodHints = Qt::ImhNone)


                        QInputDialog::getText(
                        0,
                        "Enter an Address to Validate",
                        "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)",
                        --> QLineEdit::EchoMode ??
                        --> QString& text ??
                        &ok);


                        if you set one optional parameter, you have to set all the optional paramteters to the left of that, in your case QLineEdit::EchoMode and QString& text






                        share|improve this answer

























                          2












                          2








                          2







                          the error is beacuse of the optional paramteres:



                          QString QInputDialog::getText(
                          QWidget * parent,
                          const QString & title,
                          const QString & label,
                          QLineEdit::EchoMode mode = QLineEdit::Normal,
                          const QString& text = QString(),
                          bool * ok = 0,
                          Qt::WindowFlags flags = 0,
                          Qt::InputMethodHints inputMethodHints = Qt::ImhNone)


                          QInputDialog::getText(
                          0,
                          "Enter an Address to Validate",
                          "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)",
                          --> QLineEdit::EchoMode ??
                          --> QString& text ??
                          &ok);


                          if you set one optional parameter, you have to set all the optional paramteters to the left of that, in your case QLineEdit::EchoMode and QString& text






                          share|improve this answer













                          the error is beacuse of the optional paramteres:



                          QString QInputDialog::getText(
                          QWidget * parent,
                          const QString & title,
                          const QString & label,
                          QLineEdit::EchoMode mode = QLineEdit::Normal,
                          const QString& text = QString(),
                          bool * ok = 0,
                          Qt::WindowFlags flags = 0,
                          Qt::InputMethodHints inputMethodHints = Qt::ImhNone)


                          QInputDialog::getText(
                          0,
                          "Enter an Address to Validate",
                          "Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)",
                          --> QLineEdit::EchoMode ??
                          --> QString& text ??
                          &ok);


                          if you set one optional parameter, you have to set all the optional paramteters to the left of that, in your case QLineEdit::EchoMode and QString& text







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered yesterday









                          ΦXocę 웃 Пepeúpa ツΦXocę 웃 Пepeúpa ツ

                          33.8k113965




                          33.8k113965



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55020088%2fchange-only-a-specific-default-parameter-on-a-function%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                              Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                              Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved