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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:24:45+00:00 2026-05-25T02:24:45+00:00

Example: Assuming f to be a template function, having two arguments: f (1, 2)

  • 0

Example: Assuming f to be a template function, having two arguments:

f (1, 2) In this call, does the template function assume that its arguments are int, or short, or anything else?

EDIT 1:

The template function declaration:

template <typename dataTypeA, typename dataTypeB> dataTypeB functionX (dataTypeA argA, dataTypeB argB)

  • 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-25T02:24:46+00:00Added an answer on May 25, 2026 at 2:24 am

    As @David already said, as far as your question is concerned, there’s no such thing as “making assumptions”. The literals simply have types, which are the types that a function template may use for type deduction. Remember that conversions considered as part of the template matching, though!

    So, let’s say you have this function template:

    template <typename T> void foo(T x, T y);
    

    Then if you call foo(1, 2), this will be called with T = int.

    If you say foo(1u, 2u), the deduction is T = unsigned int.

    If you say anything mixed like foo(1u, 2), there is no preferred match and the compiler will report an error.

    Since there is no short literal in C or C++, if you want to explicitly call the function foo<short>, you can either say so, or create temporary explicitshort arguments:

    foo<short int>(3, 4);
    foo<short int>(3u, 4l);  // also OK because of conversion
    foo(short(3), short(4)); // deduction
    

    Update: In light of your edit, note that since you’re only matching one argument per template parameter, you won’t have any trouble with ambiguous matching.

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

Sidebar

Related Questions

Consider this example table (assuming SQL Server 2005): create table product_bill_of_materials ( parent_product_id int
I want to write a function that calls another function with its arguments. See
I am converting an NSNumber to an NSString assuming in this example that the
Just created an acc on SO to ask this :) Assuming this simplified example:
Assuming that I have a complex type, for example: interface IFoo { IBar {get;set;}
Example: The user login to the webpage => Click on a button This action
I have created an example below to illustrate the problem I'm having. Basically, when
I want to send an email with a template like this. {% extends base.html
I developed a generic Unsigned class, or really a class template Unsigned<size_t N> that
I want to specialize a class template with the following function: template <typename T>

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.