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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:56:07+00:00 2026-06-15T03:56:07+00:00

I have overloaded methods: template<typename AnyType> void AnyFunc(AnyType &t); template<typename AnyType> void AnyFunc(AnyType &&t);

  • 0

I have overloaded methods:

    template<typename AnyType>
    void AnyFunc(AnyType &t);

    template<typename AnyType>
    void AnyFunc(AnyType &&t);

I have a caller which holds a pointer and want to use one of the functions:

    MyType* ptr=new MyType();
    AnyFunc(*ptr);

The last line runs into compile error: ambiguous overload for AnyFunc

How can I select the function I need? The simple case is to use:

    AnyFunc(std::move(*ptr)); 

which select the void AnyFunc(AnyType &&t); but this is not what I want. I need the
void AnyFunc(AnyType &t); method.

  • 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-15T03:56:09+00:00Added an answer on June 15, 2026 at 3:56 am

    Any time you have T&& v (where T is a template parameter), you have a so-called universal reference. Not only does it bind to rvalues, but also to lvalues. It’s a greedy template. It will take anything it can get and give nothing back.

    Overloading when a greedy template is involved is a bad idea, unless you know exactly what you’re doing.

    With universal references, there’s often no need to special-case lvalues vs rvalues. Just std::forward<T>(v) the parameter and the value category will be propagated.

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

Sidebar

Related Questions

I have two overloaded methods, one with an optional parameter. void foo(string a) {
for example we have BaseClass myBaseObject InheritedClass myInheritedObject and 2 overloaded methods void Do(BaseClass
I have an overloaded function which I want to pass along wrapped in a
Can I somehow have overloaded methods which differ only by generic type constraints ?
I have template with overloaded method. I'm trying to create pointer to the overloaded
I have two methods f(vector<int>& x, ....) and g(DBConn& x, ....) where the (....)
I have anchored REST services/methods to URI template by @Path annotation. It looks like
I have a template class and I want to know if it is possible
I'm trying to have overloaded methods in a web service but I am getting
I want to automatically choose the right pointer-to-member among overloaded ones based on the

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.