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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:43:24+00:00 2026-05-29T19:43:24+00:00

There is this code: #include <iostream> #include <string> #include <typeinfo> // template class template

  • 0

There is this code:

#include <iostream>
#include <string>
#include <typeinfo>

// template class
template <class U, class X, class T>
class Klasa{
public:   
    template <class Z>
    void Method(){
    }
};

// partial class specialization
template <class U>
class Klasa<U, int, U>
{
public: 
    // template method
    template <class Z>
    void Method(){
    }
};

// error occurs for that!
template <class U>
template <>
void Klasa<U, int, U>::Method<int>(){
}

int main() 
{ 
    Klasa<float, int, float> object;
    object.Method<float>();
    return 0;
} 

Compilation error:

error: invalid explicit specialization before ‘>’ token
error: enclosing class templates are not explicitly specialized
error: template-id ‘Method<int>’ for ‘void Klasa<U, int, U>::Method()’ does not match any template declaration

I try to do specialization for method

void Klasa<U, int, U>::Method<int>

, however compiler doesn’t accept it. How to write specialization for this method?

  • 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-29T19:43:25+00:00Added an answer on May 29, 2026 at 7:43 pm

    Don’t ask me for exact quotes but according to David Vandevoorde this can’t be done. The rationale is that this is essentially a partial specialization of a function template and there is no such thing. One reason to disallow this is that it is unclear what should happen with this specialization if there is a further specialization of the class: is the function specialization inherited or is it not inherited?

    Obviously, stating that this can’t be done isn’t really a lot of help. What can be done instead? A simple approach would be to delegate the implementation to an overloaded private implementation which takes e.g. a pointer argument to disambiguate between the various types. I realize that the whole point probably is to avoid the use of an extra argument, even if it is only used internally. Another possible approach could be the use of fully specialized base class: member function templates of this can be explicitly specialized.

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

Sidebar

Related Questions

Is there anyway I can modify this code example #include <stdlib.h> #include <iostream> class
This is my code #include <iostream> #include <string> #include <sys/wait.h> #include <sys/types.h> #include <unistd.h>
I have this code from programming pearls #include <iostream> //#include <string> using namespace std;
I have this code /////////////////////////////////////Gnome.cpp file #include Living.h class Gnome:public Living{ private: public: Gnome();
I'm working this source code: #include <string> #include <vector> #include <iostream> #include <istream> #include
I have the following code: #include <iostream> #include <string> void main() { std::string str;
Consider the following code: #include <iostream> template<class T> struct outer { struct inner {};
I have the following code #include <iostream> #include <cstddef> #include <string> #include <memory> class
I have this code which will include template.php file from inside each of these
There is currently this Prototype code that does a PUT: new Ajax.Request(someUrl, { method:

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.