Reputation: 2472
The following code
template<template<typename, typename> class T, typename EKeyType, typename EValueType>
class Baseclass
{
};
template<typename EKeyType, typename EValueType>
class Derived : public Baseclass<Derived, EKeyType, EValueType>
{
public:
void foo(const Baseclass<Derived, EKeyType, EValueType>& param){}
};
results in the following compilation errors:
MSVC 14: error C3200: 'Derived<EKeyType,EValueType>': invalid template argument for template parameter 'T', expected a class template
clang 3.0.0: error: template argument for template template parameter must be a class template.
However Derived
is a class template.
Everything compiles fine when I change the code to the following:
template<template<typename, typename> class T, typename EKeyType, typename EValueType>
class Baseclass
{
};
template<typename EKeyType, typename EValueType> class Derived;
template<typename EKeyType, typename EValueType>
class Derived2 : public Baseclass<Derived, EKeyType, EValueType>
{
public:
void foo(const Baseclass<Derived, EKeyType, EValueType>& param){}
};
which indicates that the error message is misleading.
What is wrong with the first code?
How can I have a template subclass inherit from a template base class, with the subclass being a template template argument of the base class and also have a member function in the subclass which takes a reference to this base class as parameter?
Upvotes: 2
Views: 135
Reputation: 119184
The first snippet is accepted by GCC and Clang. See here.
I seem to recall that MSVC has a bug where it considers Derived
to refer to the injected class name, rather than the template name. However, the standard is quite clear that when the name of the enclosing class is used as an argument to a template template parameter, it should be interpreted as a template ([temp.local]/1), so your code is fine.
It appears that the old version of Clang you are using might have the same bug.
As a workaround, you can write ::Derived
to force it to find the template name, not the injected class name.
Upvotes: 3