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 8661031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:23:54+00:00 2026-06-12T16:23:54+00:00

I want to achieve this: – second parameter by default set to first argument

  • 0

I want to achieve this:

- second parameter by default set to first argument

Something like:

int foo (int a, int b = a);

But how to do that?

Thanks a lot!

  • 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-06-12T16:23:55+00:00Added an answer on June 12, 2026 at 4:23 pm

    This is forbidden by:

    8.3.6 Default arguments [dcl.fct.default]

    9) Default arguments are evaluated each time the function is called.
    The order of evaluation of function arguments is unspecified.
    Consequently, parameters of a function shall not be used in default
    argument expressions, even if they are not evaluated.
    Parameters of a
    function declared before a default argument expression are in scope
    and can hide namespace and class member names. [ Example:

    int a;

    int f(int a , int b = a); / / error: parameter a

    / / used as default argument

    typedef int I;

    int g( float I , int b = I (2)); / / error: parameter I found

    int h(int a , int b = sizeof (a )); / / error, parameter a used

    / / in default argument

    —end example ]

    An alternative is overloading:

    int foo(int a, int b);
    
    int foo(int a)
    {
       return foo(a,a);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to achieve something like this: class C { int m_nVal; public: C(int
I want to achieve something like this in C# 3.5: public void Register<T>() :
I want to achieve something like this inside a UIView: I have created a
I made something like this: http://static.cmslog.com/testapp/google/terrain What I want to achieve now is terrain
I want to achieve this using html and css: I have tried to set
With Django models, I want to achieve this: class Foo(models.Model): name = models.CharField(max_length=50) #wrapping
I want to achieve this view: I can do it with tables but when
I want to achieve this kind of functionality with twisted but I cant seem
I don't know if it's possible but i want to achieve this: i have
I want to achieve this effect: When the user focus a text area within

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.