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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:51:59+00:00 2026-05-15T17:51:59+00:00

Can I overload a function which takes either a reference or variable name? For

  • 0

Can I overload a function which takes either a reference or variable name?

For example when I try to do this:

void function(double a);
void function(double &a);

I would like the caller of this function to be able to do:

double a = 2.5;
function(a); // should call function(double &a)
function(2.3); // should call function(double a)

I would like to write pass-by-reference functions for better memory use and possible manipulation of the variable outside of scope, but without having to create a new variable just so I can call the function.

Is this possible?

Cheers

  • 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-15T17:52:00+00:00Added an answer on May 15, 2026 at 5:52 pm

    I think you’re missing the point here. What you really should have is JUST this:

    void function(const double &a);
    

    Note the “const”. With that, you should always get pass-by-reference. If you have non-const pass by reference, then the compiler will correctly assume that you wish to modify the passed object – which of course is conceptually incompatible with the pass-by-value variant.

    With const references, the compiler will happily create the temporary object for you behind your back. The non-const version doesn’t work for you, because the compiler can only create these temporaries as “const” objects.

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

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It sounds more like the problem is in your subforms… May 16, 2026 at 9:15 am
  • Editorial Team
    Editorial Team added an answer You could use suppression tags in the generated files: //!… May 16, 2026 at 9:15 am
  • Editorial Team
    Editorial Team added an answer You don't need that .click() handler/wrapper underneath, just the .delegate()… May 16, 2026 at 9:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

It must be something specific in my code, which I can't post. But maybe
I've been working on getting this program complete where it saves multiple structs to
This is a C# question, but really could be language-agnostic I have inherited a
I actually have two questions regarding the same problem but I think it is
In a project I'm working on, I have a Score class, defined below in
There's a standard pattern for events in .NET - they use a delegate type
Looking at System.Collections.Generic.Dictionary<TKey, TValue> , it clearly implements ICollection<KeyValuePair<TKey, TValue>> , but doesn't have
Here's an interesting question about the various quirks of the C++ language. I have
I just came across various overloading methods like type of parameter passed, varying number

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.