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

  • Home
  • SEARCH
  • 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 8735541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:04:59+00:00 2026-06-13T10:04:59+00:00

Well suppose there is a function void fun(const MyStructure& argu1 = MyStructure(), MyStructure& argu2

  • 0

Well suppose there is a function

void fun(const MyStructure& argu1 = MyStructure(), MyStructure& argu2 = Mystructure())

argu2 isn’t const because I want to modify its value in the function.

To call the function:

MyStructure a; 
MyStructure b; 
fun(a,b);

The build succeeds in windows but fails in Linux and the error is

default argument for parameter of type 'MyStructure&' has type 'MyStructure'

But the build succeeds both in windows and in linux if I remove the second default argument which is non-const… Can anybody tell me why and how to solve it?

  • 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-13T10:05:00+00:00Added an answer on June 13, 2026 at 10:05 am

    You can use overloading to let you manually handle an optional second non-const reference argument:

    void fun( MyStruct const& arg1, MyStruct& arg2)
    {
        // do the real work
    }
    
    void fun( MyStruct const& arg1 = MyStruct())
    {
        MyStruct arg2;  // a dummy argument that can be changed, but we'll
                        //  throw those changes away
        fun( arg1, arg2);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I want to write a function in R which is a function of
Suppose you have the following non-static member function: // .h struct C { void
A) suppose a table. that i want to perform a DELETE function on .
Suppose I want to make a function that recursively parses a variadic argument list,
Suppose i have the code snippet as follows : ( clarification purpose/not well formed
Well, the title pretty much states it. I want to be able to draw
well there are 3 activities say Act1 , Act2 and Act3 . in Act1
I'm trying to refactor a fairly hefty view function in Django. There are too
Suppose you have the following code template<typename T,void (T::*m)(int)> struct B{ void f(T* a,int
Well, three questions in less then 24 hours.But I suppose the lack of any

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.