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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:21:07+00:00 2026-06-01T10:21:07+00:00

If you overload a function and then call it with an argument that perfectly

  • 0

If you overload a function and then call it with an argument that perfectly matches one of the overloads

int f(int){return 3;}
int f(bool){return 4;}
...        //inside main()
f(1);      //Calls f(int)

the compiler simply chooses this (perfect) match before attempting any implicit conversions. However I’ve been trying to overload a function tempĺate as in

template <bool veracity>
int f(){return 1;}

template <int amount>
int f(){return 2;}

...        //inside main()
f<1>();

but the compiler keeps complainning about ambiguous call to the overloaded f(), stating it could be either f<true>() or f<1>(). Shouldn’t the compiler just choose the perfect match, instead of trying to convert 1 to true ?

I was under the impression that implicit conversion for template arguments was actually more restrictive than implicit conversion of function arguments. Is there a way to get around this problem?

  • 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-01T10:21:09+00:00Added an answer on June 1, 2026 at 10:21 am

    The argument you’re supplying isn’t a type, it’s a value, so the rules are a bit different — you need to apply the rules for non-type arguments. For non-type arguments, implicit conversions are allowed. §14.3.2/5:

    The following conversions are performed on each expression used as a non-type template-argument. If a non-type template-argument cannot be converted to the type of the corresponding template-parameter then the program is ill-formed.

    — For a non-type template-parameter of integral or enumeration type, conversions permitted in a converted constant expression (5.19) are applied.

    In C++03, the wording is marginally different, but the effect essentially identical (also §14.3.2/5):

    — for a non-type template-parameter of integral or enumeration type, integral promotions (4.5) and integral conversions (4.7) are applied.

    Either way, since 1 is both an int and implicitly convertible to a bool, your call is ambiguous.

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

Sidebar

Related Questions

I recently discovered that in C++ you can overload the function call operator, in
I want to overload a function so that it manipulates its argument in some
Which Activator.CreateInstance overload function to call? I have a type returned from Type proxyType
Why is it not possible to overload a function just by changing the return
Possible Duplicate: «F(5)» and «int x; F(x)» to call different functions? Can we overload
If I have a function overload set similar to template<typename T> void f(T&& t,
Is it possible to overload the default function operator (the () operator) in C#?
Regarding the question on SO How to overload the calling process of any function
I am trying to overload operator<< as a member function. It works if simply
There are multiple overloads for sqlcommand.Parameters.Add(...) function. Some of them do not take size,

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.