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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:27:32+00:00 2026-06-10T03:27:32+00:00

Reading this question made me wonder: is there a technical reason for disallowing class

  • 0

Reading this question made me wonder: is there a technical reason for disallowing class templates overloads?

By overloading, I mean having several templates with the same names, but different parameters, for instance

template <typename T>
struct Foo {};

template <typename T1, typename T2>
struct Foo {};

template <unsigned int N>
struct Foo {};

The compiler manages to handle overloaded functions and function templates, wouldn’t it be possible to apply the same techniques (e.g. name mangling) to class templates?

At first, I thought that perhaps that would cause some ambiguity issues when taking the template identifier alone, but the only time this can happen is when passing it as a template template argument, so the type of the parameter could be used to choose the appropriate overload:

template <template <typename> class T>
void A {};

template <template <unsigned int> class T>
void B {};

A<Foo> a; // resolves to Foo<T>
B<Foo> b; // resolves to Foo<N>

Do you think such feature could be useful? Is there some “good” (i.e. technical) reasons why this is not possible in current C++?

  • 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-10T03:27:33+00:00Added an answer on June 10, 2026 at 3:27 am

    Section 12.5 from Templates the Complete Guide (Amazon) contains this quote:

    You may legitimately wonder why only class templates can be partially specialized. The reasons are mostly historical.
    It is probably possible to define the same mechanism for function templates (see Chapter 13).

    In some ways the
    effect of overloading function templates is similar, but there are also some subtle differences. These differences are
    mostly related to the fact that the primary template needs to be
    looked up when a use is encountered. The specializations are
    considered only afterward, to determine which implementation should be
    used.

    In contrast, all overloaded function templates must be brought
    into an overload set by looking them up, and they may come from
    different namespaces or classes. This increases the likelihood of
    unintentionally overloading a template name somewhat.

    Conversely, it
    is also imaginable to allow a form of overloading of class templates.
    Here is an example:

    // invalid overloading of class templates
    template<typename T1, typename T2> class Pair; 
    template<int N1, int N2> class Pair; 
    

    However, there doesn’t seem to be a pressing need for
    such a mechanism.

    Furthermore, the Design and Evolution of C++ (Amazon) contains this quote in section 15.10.3

    I therefore concluded that we needed a mechanism for “specializing”
    templates. This could be done either by accepting general overloading
    or by some more specific mechanism. I chose a specific mechanism
    because I thought I was primarily addressing irregularities caused by
    irregularities in C and because suggestions of overloading invariably
    creates a howl of protests. I was trying to be cautious and
    conservative; I now consider that a mistake. Specialization as
    originally defined was a restricted and anomalous form of overloading
    that fitted poorly with the rest of the language.

    Bold emphasis mine. I interpret this as saying that function overload resolution is more difficult to implement (and get right by users) than class specialization. So probably no real technical obstacles (similary for function template partial specialization) but an historical accident.

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

Sidebar

Related Questions

Reading this fascinating question made me remember a code snippet I stumbled across a
I was reading through older questions and this one made me wonder how you
I was reading this question and then I made the following. a = b
After reading this question, I need to clear up some things. IQueryable<Customer> custs =
After reading this question , i saw the answer by Naveen containing a link
I was reading this question, but didn't understand some part of the aix's answer
I was reading this question (which you do not have to read because I
Now that it's answered: Don't bother reading this question, it's a bit lengthy and
I was reading over this question and wondered if the accepted answer might also
So, I was reading this earlier question for ideas on how to allow me

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.