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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:33:21+00:00 2026-06-15T20:33:21+00:00

Possible Duplicate: Template partial specialization with multiple template argument error Is is possible to

  • 0

Possible Duplicate:
Template partial specialization with multiple template argument error

Is is possible to specialize e template class as function level?

I’ll give you and example with what I want to achieve, but I get compilation errors:

template<typename T1, typename T2>
class C
{
    public:
        void f();
};

template<typename T1, typename T2>
void C<T1, T2>::f()
{
}

template<typename T1, int>
void C<T1, int>::f()
{
}

Errors:

template argument list following class template name must list parameters in the order used in template parameter list
'void C<T1,T2>::f(void)' : function template has already been defined
'C<T1,T2>': template parameter 'T2' is incompatible with the declaration
  • 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-15T20:33:22+00:00Added an answer on June 15, 2026 at 8:33 pm

    If you want to make the behaviour of C::f dependent on T2 you can try to put its implementation into a separate class like the following:

    template <typename T>
    class C_aux
    {
    public:
        void f() {}
    };
    
    template <>
    class C_aux<int>
    {
        void f() {}
    };
    
    template <typename T1, typename T2>
    class C
    {
        public:
            void f();
    };
    
    template <typename T1, typename T2>
    void C<T1, T2>::f()
    {
        C_aux<T2>::f();
    }
    

    Depending on the details of your needs C_aux::f has to take extra parameters. Or you can let class C inherit from class C_aux or vice versa.

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

Sidebar

Related Questions

Possible Duplicate: “invalid use of incomplete type” error with partial template specialization Why is
Possible Duplicate: partial specialization of function template I can't find anywhere a solution for
Possible Duplicate: Specialization of templated member function in templated class template <class T> class
Possible Duplicate: Templates: template function not playing well with class’s template member function template
Possible Duplicate: trailing return type using decltype with a variadic template function I want
Possible Duplicate: using a template class without a template argument If I have a
Possible Duplicate: Can a member function template be virtual? In a base class, the
Possible Duplicate: Confusing Template error I have a templated class with a templated method.
Possible Duplicate: Error calling template method in templated-base-class The following code compiles with MSVC10
Possible Duplicate: How do I define a template function within a template class outside

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.