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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:32:09+00:00 2026-06-06T19:32:09+00:00

Look at the code: template <class x> struct Foo { int getX(x *p) {

  • 0

Look at the code:

template <class x> struct Foo
{
    int getX(x *p) { return(0); }
    enum E12 { a };
};

template <> int Foo<int>::getX(int*)
{
    return(-15);
}

template <> enum Foo<int>::E12
{
    a, b, c
}

As it was discussed in Cannot overload function, the first specialization is legal and even works in MSVC. While the second specialization for enum does not even want to compile, saying “error C2988: unrecognizable template declaration/definition”.

It seems to me that C++ is making relaitively unlogical exception for methods. Enum is just an example. The same thing can be applied to member classes, typedefs, etc.

I will be happy is some body will comment on this.

  • 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-06T19:32:10+00:00Added an answer on June 6, 2026 at 7:32 pm

    This is a very obscure new feature of C++11. File a bug report with Microsoft, although it is unlikely it will be given priority as almost nobody is aware this is allowed. The correct syntax would be

    template <class x> struct Foo
    {
        int getX(x *p) { return(0); }
        enum E12 { a };
    };
     
    template <> int Foo<int>::getX(int*)
    {
        return(-15);
    }
     
    template <> enum Foo<int>::E12
    {
        a, b, c
    };
    

    I’ve filed a bug with GCC. Can someone test on recent Clang?


    In C++03, only classes and functions may be explicitly specialized. From the standard, C++03 14.7.3/1:

    An explicit specialization of any of the following:

    • function template
    • class template
    • member function of a class template
    • static data member of a class template
    • member class of a class template
    • member class template of a class or class template
    • member function template of a class or class template

    can be declared by a declaration introduced by template<>

    A member enum is not such a case. (Generally speaking, an enum type is always defined only once at its first declaration.)

    To obtain a templated enum or typedef, you can wrap it in a class template. In your case, it would be a member class template of Foo. Such a construct is called a metafunction.

    C++11 also has alias templates, which are like templated typedefs, but they cannot be explicitly specialized.


    The policy of only allowing classes and functions to be specialized, and then allowing such templates to encapsulate other things like enum and typedef, seems more consistent to me than allowing direct specialization of enum. But, perhaps the language is going in your preferred direction.

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

Sidebar

Related Questions

Look at following code: template <typename T, int d> class Grid { //Following line
Please take a look at this code: template<class T> class A { class base
look at this code, <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <script> function change() {
Look at this code: class MyClass(): # Why does this give me NameError: name
Look at this code please: #include <iostream> using namespace std; class Ratio { public:
First look at this code: class Program { static void Main(string[] args) { var
Please look at this code: @interface myObject:NSObject -(void)function:(id)param; @end @implementation myObject -(void)function:(id)param { NSLog(@BEFORE);
I look in documentation and source code but cannot figure out how to get
Here is my code: class Controller_Call extends Controller { public $template = 'tpl/default'; public
Code: #include Node.h #include vector.h #include algorithm.h struct PlusPoint { bool used; int id;

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.