Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 920575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:44:15+00:00 2026-05-15T18:44:15+00:00

I have to add a default int& argument (Eg iNewArgument) to an existing function

  • 0

I have to add a default int& argument (Eg iNewArgument) to an existing function definition in a header file:

What is the syntax to initialize the last argument to make it take a default value?

..
virtual int ExecNew
    (int& param1, int& RowIn,int& RowOut, char* Msg = '0', 
            bool bDebug=true, int& iNewArgument = NULL ) = 0 ;
.
.

NULL is #defined to 0

Error: default argument: cannot convert from int to int&

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:44:16+00:00Added an answer on May 15, 2026 at 6:44 pm

    Your example indicates that you are creating a virtual function. Default arguments in virtual (especially pure) functions are not a good idea, because they are not considered when you call an overridden function.

    struct A {
      virtual void f(int = 4711) = 0;
    };
    
    struct B : A {
      virtual void f(int) { /* ... */ }
    };
    

    Now, if someone calls f on a B object, he will have to provide the argument – the default isn’t used. You would have to duplicate the default argument in the derived class, which creates ugly redundancies. Instead, you can use the non-virtual interface pattern

    struct A {
      void f(int a) {
        int out;
        f(a, out);
      }
    
      void f(int a, int &out) {
        doF(a, out);
      }
    
    protected:
      virtual void doF(int a, int out&) = 0;
    };
    

    The user can now call f with one, and with two arguments, from whatever class type he calls the function, and the implementers of A don’t have to worry about the default argument. By using overloading instead of default arguments, you don’t need to break your head around lvalues or temporaries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I take a jar file that I have and add it to
I have a requirement to add conditional disabled & class attributes to a dropdown
Let's say I have defined a route: routes.Add(new Route(Users/{id}, new MvcRouteHandler()) { Defaults =
I have Excel add-in which I add so many class modules that it is
I have to add a coupon table to my db. There are 3 types
I have to add either an embed tag for Firefox or an object tag
hi i forgot the code which in a sample class you have to add
I've created an excel sheet with Delphi 6. Now I have to add a
I have two functions to add and remove table rows that contain a form
Is there a convention for naming the private method that I have called _Add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.