Referring to a base class with template template parameters

Ian Lance Taylor iant@google.com
Sun Nov 8 07:20:00 GMT 2009


Deth <alexrepair@gmail.com> writes:

> I'm having issues referring to a base class under specific circumstances, and
> am hoping that someone can provide a work-around.
>
> I have a base class A with a template template parameter T:
>
> template <template <typename> class T>
> class A {
> public:
>    A(int) {}
> };
>
> I then have a templated child class that derives from A using CRTP:
>
> template <typename>
> class B : public A {
> public:
>    B(int i)
>       : A(i) {}
> };
>
> gcc reports the following error on the line with B's constructor initializer
> list:
> "error: expected a class template, got 'B< <template-parameter-1-1> >
>
> I can accomplish this in Visual Studio, but I can't find the syntax to make
> it work in gcc v4.2.1



I don't know why your code would work in Visual Studio.  To me it
looks wrong in several places.

This code works in gcc, and I believe is standard conformant.


template <typename T>
class A {
public:
   A(int) {}
};

template <typename T>
class B : public A<B<T> > {
public:
   B(int i)
     : A<B<T> >(i) {}
};


Ian



More information about the Gcc-help mailing list