template template parameter used as base class of ref class error

G

Guest

I get a C2811 error when I compile the following (with the /clr switch):

template <class T>
ref class Base
{};

template <template <class> class TBase>
ref class Derived
: TBase<int>
{};

error C2811: 'Derived<TBase>' : cannot inherit from 'TBase<int>', a ref
class can only inherit from a ref class or interface class.

However, if I add a self-referential typedef to the Base class and reference
the typedef in the derivation, everything compiles fine:

template <class T>
ref class Base
{
public:
typedef Base Type;
};

template <template <class> class TBase>
ref class Derived
: TBase<int>::Type // this is acceptable
{};

Is this expected behavior?
 
B

Ben Voigt

RitualDave said:
I get a C2811 error when I compile the following (with the /clr switch):

template <class T>
ref class Base
{};

template <template <class> class TBase>
ref class Derived
: TBase<int>
{};

error C2811: 'Derived<TBase>' : cannot inherit from 'TBase<int>', a ref
class can only inherit from a ref class or interface class.

However, if I add a self-referential typedef to the Base class and
reference
the typedef in the derivation, everything compiles fine:

template <class T>
ref class Base
{
public:
typedef Base Type;
};

template <template <class> class TBase>
ref class Derived
: TBase<int>::Type // this is acceptable
{};

Is this expected behavior?

The second case is not evaluated until template instantiation, because it
refers to an element of the class, which isn't known during template
parsing.

I don't know if this will work, but can you try changing class to ref class:
template <template <class> ref class TBase>
ref class Derived
: TBase<int>
{};
 
G

Guest

Yeah, I had given that a try as well. No luck.

Ben Voigt said:
The second case is not evaluated until template instantiation, because it
refers to an element of the class, which isn't known during template
parsing.

I don't know if this will work, but can you try changing class to ref class:
template <template <class> ref class TBase>
ref class Derived
: TBase<int>
{};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top