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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:41:46+00:00 2026-06-17T16:41:46+00:00

Why this is ambiguous? template<class T> void g(T) {} // 1 template<class T> void

  • 0

Why this is ambiguous?

template<class T> void g(T)  {}   // 1
template<class T> void g(T&) {}   // 2

int main() {
    int  q;
    g(q);
}

I understand that this is partial ordering context. And my, possibly erroneous, thinking is: any T& from #2 can be put in #1, but not any T from #1 is legit in #2. So partial ordering should work.

  • 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-17T16:41:47+00:00Added an answer on June 17, 2026 at 4:41 pm

    OK. I think this is what you’re looking for. Not diving into the twice-application of the parameter vs. argument type comparison, the following in the standard leaps out at me:

    C++11 §14.8.2.4p5

    Before the partial ordering is done, certain transformations are performed on the types used for partial ordering:

    • If P is a reference type, P is replaced by the type referred to.
    • If A is a reference type, A is replaced by the type referred to.

    C++11 §14.8.2.4p6 goes on to talk about what happens when both are reference types, but that isn’t applicable here (though also an interesting read). in your case, only one is, so it is stripped. From there:

    C++11 §14.8.2.4p7

    Remove any top-level cv-qualifiers:

    • If P is a cv-qualified type, P is replaced by the cv-unqualified version of P.
    • If A is a cv-qualified type, A is replaced by the cv-unqualified version of A.

    Now both are completely equal, and thus you have your ambiguity, which I believe is solidified from C++11 §14.8.2.4p10. The text of C++11 §14.8.2.4p9 covers both being reference types which, again, is not the case here:

    C++11 §14.8.2.4p10

    If for each type being considered a given template is at least as specialized for all types and more specialized for some set of types and the other template is not more specialized for any types or is not at least as specialized for any types, then the given template is more specialized than the other template. Otherwise, neither template is more specialized than the other.

    But reading the standard in this section is like deciphering greek to me, so I may be way off base. (no offense to the Greeks =P).

    It did, however, make me think "a const T& against a T, given the same invoke condition g(q), should also be ambiguous if everything I just read is enforced as-written." Sure enough, I tried it, and the same ambiguity was flagged.

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

Sidebar

Related Questions

Program :main.cpp struct X { int x; }; export template <class T> T const&
So given the following template functions with partial specialization template<typename T> void foo(vector<T> &in)
I cant see why the statement in main is ambiguous. template<class T, class U,
I don't understand why this code fails to compile in main() due to ambiguous
#include stdafx.h #include Record.h template<class T>//If I make instead of template regular fnc this
consider the following program: namespace NS2 { class base { }; template<typename T> int
I have overloaded methods: template<typename AnyType> void AnyFunc(AnyType &t); template<typename AnyType> void AnyFunc(AnyType &&t);
I have this template set __Self &set(const char *name, lua_CFunction func) { return rawSet(name,
Consider the following: template <typename T> class testString { public: typedef T* iterator; void
How can I create an interface class, something like this : template<typename file_system_t> class

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.