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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:14:34+00:00 2026-06-10T02:14:34+00:00

Given following code template<typename T> struct A{ struct In{}; }; template<typename T> struct Desc{

  • 0

Given following code

template<typename T>
struct A{
  struct In{};

};

template<typename T>
struct Desc{
};


template<typename X>
struct Desc<typename A<X>::In> {
};



int main(){
  Desc<A<int>::In> a;
}

the compiler refuses the Desc specialization with

error: template parameters not used in partial specialization:
error:         ‘X’

Same if the struct is defined by

template<>
template<typename X>
struct Desc<typename A<X>::In> {
};

Definition

template<typename X>
template<>
struct Desc<typename A<X>::In> {
};

gives the error

desc.cpp:14:10: error: invalid explicit specialization before ‘>’ token
desc.cpp:14:10: error: enclosing class templates are not explicitly specialized
desc.cpp:15:8: error: template parameters not used in partial specialization:
desc.cpp:15:8: error:         ‘X’

Is this a case of “non-deduced context” as here?

Template parameters not used in partial specialization

It would make sense, since there’s no guarantee that the inner class is actually a class (we know only that it is a typename, it may be a typedef).
Is there then a way to specify it’s a real class?

  • 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-10T02:14:36+00:00Added an answer on June 10, 2026 at 2:14 am

    Is there then a way to specify it’s a real class

    No, there is no way to specify, if you use this type in partial template specialization.

    There are only two ways. Specialize Desc for concrete A, so,

    template<>
    struct Desc<typename A<type>::In> { };
    

    or use something like

    template<typename T, typename  = void>
    struct Desc{
    };
    
    
    template<typename X>
    struct Desc<X, typename A<X>::In> {
    };
    

    or of course specialize for type A<X> not for A<X>::In.

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

Sidebar

Related Questions

Following code gives compiler error which is expected ( Demo ): 1 template<bool> struct
Given the following piece of code: template<typename T> class MyContainer { typedef T value_type;
please consider the following code: template <typename T> struct foo { template <typename S>
Look at following code: template <typename T, int d> class Grid { //Following line
Given the following code: void f() { class A { template <typename T> void
The following code: template <typename S, typename T> struct foo { void bar(); };
Given following code, #include <sstream> #include <stdint.h> template <typename D> void func() { std::basic_stringstream<D>
Given the following code which I can't get to compile. template < typename OT,
I have the following code: template<typename Parent, typename T, void (Parent::*Setter)(T), T (Parent::*Getter)()> struct
I have the following test code #include <iostream> template <typename T> struct PS {

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.