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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:59:30+00:00 2026-06-18T01:59:30+00:00

I have an issue with the use of aliases in function arguments. Here is

  • 0

I have an issue with the use of aliases in function arguments. Here is my problem.

Let’s consider this function definition

void thisIsSparta(int& number){
    ...
}

at call time, it works perfectly well with the following code :

int king = 1;
thisIsSparta(king);

but I have a mismatch error when I try this :

thisIsSparta(1);

I can easily guess that the error occurs because there is simply no variable to alias, hence the error. However, I don’t want the programmer to worry about using only one of the two approaches, this second function call should work as fine !

The only solution I see is to create another function with no alias argument, in addition to the first one :

void thisIsSparta(int number){

}

But this would result in an awful code duplication, and I’m not a huge fan of this.

Furthermore, the program could decide to use this second definition instead of the former when I use a variable. I then loose the interest of the alias, whose purpose is to avoid variable copy.

Does anyone have a solution to my problem ? Indeed, this is a simplified example, in practice I have a generic type in argument for this function, and it could be arbitrarily big. This is why I’d like to use an alias to avoid copy.

  • 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-18T01:59:31+00:00Added an answer on June 18, 2026 at 1:59 am

    For basic types, just pass by value. It’s faster than passing a reference, so ditch the passing by reference and just have

    void thisIsSparta(int number)
    

    For large types, you can only bind temporaries to const references, so you can declare the method as

    void thisIsSortOfSparta(const MyClass& obj)
    

    If you’re modifying the value inside the function, then passing a temporary as argument doesn’t make sense, so the compiler is right to complain, but in case you don’t, use the above two options.

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

Sidebar

Related Questions

I have an issue regarding Sendkeys Class, as i want to use this class
I have this issue with password encryption, now, I use md5.. i know it's
I have issue about convert XML to Java Object , in here i use
I have an issue with Mozilla, i use this client side JavaScript code in
I have an issue. I use this code: var test='test'; $('#tip').delay(1000).html(test); That doesn't work,
I have been on this issue for a couple days now. I use zsh
i have an issue i could use some help with, i have python list
I have an issue with an object I created and then use in a
I am completely stumped with how to use .htaccess and I have an issue
I rarely use SQL and have a unique issue I need to solve. I

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.