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

  • Home
  • SEARCH
  • 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 7871983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:04:30+00:00 2026-06-03T02:04:30+00:00

The following gives me a couple compile errors: error C2995: ‘void A<T>::B<Q>::func(void)’ : function

  • 0

The following gives me a couple compile errors:

error C2995: 'void A<T>::B<Q>::func(void)' : function template has already been defined
error C3855: 'A<T>::B<Q>': template parameter 'Q' is incompatible with the declaration

How can I do this without having the definitions in the class declaration?

template<typename T>
struct A
{
    template<typename Q>
    struct B
    {
        void func();
    };
};

template<typename T>
template<typename Q>
void A<T>::B<Q>::func()
{
}

template<typename T>
template<>
void A<T>::B<int>::func()
{
}

Edit:

According to 14.7.3 §16 a nested class template cannot be specialized if it’s enclosing class template is not also specialized. However, that makes me wonder why the nested class specialization works when it’s completely defined within the outer class declaration like so:

template<typename T>
struct A
{
    template<typename Q>
    struct B
    {
        void func(){}
    };

    template<>
    struct B<int>
    {
        void func(){}
    };  
};

Perhaps this is just VS2010 allowing me to do something I shouldn’t be able to do?

  • 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-03T02:04:31+00:00Added an answer on June 3, 2026 at 2:04 am

    The problem is in the fact that you need to be able to declare the templated type when you use the class (or struct).

    So, if you have a templated nested class, its type would need to be set in the class itself, because you won’t be able to do that from the “outside”.
    for example:

    template<typename T>
    struct A
    {
        template<typename Q>
        struct B
        {
            void func(){}
        };
    };
    

    Now, lets say you’d want to declare a variable of type A<int> with B<int> … how would you do it ?

    A<int>::B<int> a; //this syntactically would mean a is of type B<int>
    A<int,int> a; //this would mean A is a templated class with 2 templated types
    

    So, you can’t really access B in the declaration.
    So, B‘s type has to be set within the class A.

    Nested Class Templates

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

Sidebar

Related Questions

The following gives me the error Uncaught SyntaxError: Unexpected identifier : $('span.xtro').html(''); $('span.xtro').html('<input type='button'
Any ideas why does the entity framework in LINQ gives following strange error: Unable
The following C++ code gives an error while compiling: #include<iostream> using namespace std; class
My program installation sometimes gives the following error in the installer log: `Failed to
I know this has been asked and answered a couple times already, but I'm
Running the following query in SQL Server Management Studio gives the error below. update
The following command gives many manuals of Zsh man zsh<tab> alt text http://dl.getdropbox.com/u/175564/zsh.png I
The following code gives a NullReferenceException since XPathSelectElement can't navigate through the XPath expression
I'm having problems the following code gives me no results. however if I uncomment
when i am analyze my project following code gives me leakage warning. is there

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.