0

GCC 7.5.0 is giving me an error message that I'm puzzled about. This is the smallest piece of code I can come with that generates the message:

template<template<typename> typename>
struct A
{

};

template<char>
struct X
{
    template<typename>
    struct Y
    {

    };
};

template<char c>
struct B : public A<X<c>::Y>
{

};

GCC 7.5.0 says:

../main.cpp:18:28: error: type/value mismatch at argument 1 in template parameter list for ‘template<template<class> class<template-parameter-1-1> > struct A’
subdir.mk:18: recipe for target 'main.o' failed
 struct B : public A<X<c>::Y>
                            ^
../main.cpp:18:28: note:   expected a class template, got ‘X<c>::Y’

Is the problem perhaps that the argument to A in the inheritance clause must be a class template that sits at namespace level? This is not the case with X::Y. Unfortunately, I do not know how to do without putting Y inside of X. Application-specific stuff not shown seems to mandate it.

1 Answers1

3

You need to tell the compiler that X<c>::Y is a template and not a type or variable. Try the following:

template<char c>
struct B : public A<X<c>::template Y>
{

};

Demo here

For a rather longer discussion of exactly when you need to specify this kind of thing and why, this question is very thorough.

Nathan Pierson
  • 5,461
  • 1
  • 12
  • 30