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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:21:08+00:00 2026-06-02T09:21:08+00:00

Why does compiler allow this? #include <iostream> using namespace std; template<typename T> void func(T

  • 0

Why does compiler allow this?

#include <iostream>
using namespace std;

template<typename T>
void func(T t)
{
    cout<<"The value is :"<<t<<"\n";
}

template<>
void func<int>(int d)    //Template Specialization
{
    cout<<"Template function\n";
}

void func(int d)        //Non-template function with same name & signature
{
    cout<<"Non-template function\n";
}

int main()
{
    func(4);
    func(4.67);
    func("TENE");
}
  • 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-02T09:21:11+00:00Added an answer on June 2, 2026 at 9:21 am

    The answer to the question lies in section 13.3.3

    Given these definitions, a viable function F1 is defined to be a better function than another viable function F2 if for all arguments i, ICSi(F1) is not a worse conversion sequence than ICSi(F2), and then

    — for some argument j, ICSj(F1) is a better conversion sequence than ICSj(F2), or, if not that,

    — F1 is a non-template function and F2 is a function template specialization, or, if not that,

    — F1 and F2 are function template specializations, and the function template for F1 is more specialized than the template for F2 according to the partial ordering rules described in 14.5.5.2, or, if not that, …

    So amongst the three choices (non-templated func, specialization of func<int>, and the generic template func<typename T>, the non-template version of func is the best. Since there is a perfect match here, there is no reason for the compiler to even look to the templated versions of the function.

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

Sidebar

Related Questions

In forward referencing language such as c#, how does the compiler handle this? What
When using plain C in iPhone development, does the compiler place the variables declared
Why does the C# compiler not even complain with a warning on this code?
The min algorithm is normally expressed like this: template <typename T> const T& min(const
Why does this code fail to compile with VS 2005: #include <boost/bind.hpp> #include <boost/function.hpp>
How does virtual functions work behind the scenes in Inheritance ? Does the compiler
I was wondering if there is a possible optimization where the compiler does not
Consider the code below. I don't understand why my GCC compiler does not try
__thread Foo foo; How is foo actually resolved? Does the compiler silently replace every
How does an interpreter/compiler work? What is the difference between interpreter and compiler.

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.