There is no class template named X in the class template

When trying to compile this (CRTP-like) code with GCC 4.6.0:

template<template<class> class T> struct A;

template<class T> 
struct B: A<B<T>::template X> {
    template <class U> struct X { U mem; };
};

B<int> a;

I get errormessage "test.cpp: 3: 26: error: no class template named" X in "struct B <int>". Why does X seem invisible outside the class definition?

+5
source share
3 answers

How to Emile Cormier points out here , the problem is that in the place of creation A, Bis still incomplete type, and you can not use the inner template.

X B. T B, , , :

template <typename T>
struct inner_template 
{
   template <typename U> class tmpl { U mem; }; // can specialize for particular T's
};
template <typename T>
struct B : A< inner_template<T>::template tmpl >
{
};
+4

struct B - , A<B<T>::template X> .

+2

B B, . , :

template<template<class> class T> struct A {};

struct B : public A<B::nested>
{
        struct nested {};
};
+1

All Articles