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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:31:52+00:00 2026-05-17T21:31:52+00:00

I found that template method could be overloaded, can I do the same on

  • 0

I found that template method could be overloaded, can I do the same on template classes? If 2 template classes match a template class instantiation, we can use the parameter type in the constructor to deduce which one to use.

template <typename T>
class A{
  A(T){}
};

template <typename T>
class A{
  A(T*){}
};

int main(){
  A<int*> a((int*)0);
  A<int> a((int*)0);
  return 0;
}
  • 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-17T21:31:53+00:00Added an answer on May 17, 2026 at 9:31 pm

    No. This is not allowed. Instead class template can be specialized (including partial specialization). This pretty much achieves the effect of overloading (which is only for functions)

    Note that template parameters can not be deduced from constructor arguments.

    template<class T> struct X{
       void f(){}
    };
    
    template<class T> struct X<T*>{
       void f(){}
    };
    
    int main(){
       X<int> x;
       x.f();          // calls X<T>::f
    
       X<int *> xs;
       xs.f();         // calls X<T*>::f
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`m trying to display classes that have properties of type some custom class inside
I've found that on some occasions I can edit the source while debugging. Are
I have found that there is generally a singe type or namespace that takes
Whilst refactoring some legacy C++ code I found that I could potentially remove some
We’ve found that the unit tests we’ve written for our C#/C++ code have really
I have found that my HTML is, to be honest, very clunky. Small, simple
I've installed Ubuntu Server (8.04) into Parallels and found that the system time/clock ran
I've been parsing through some log files and I've found that some of the
I'm using a RichTextBox in WinForms 3.5 and I found that when I programmatically
After trying to setup my site for Google Webmaster Tools I found that my

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.