470,849 Members | 652 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

template template parameter used as base class of ref class error

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?
Jun 14 '06 #1
2 2083
"RitualDave" <Ri********@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com...
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>
{};

Jun 14 '06 #2

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

"Ben Voigt" wrote:
"RitualDave" <Ri********@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com...
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>
{};

Jun 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Istvan Buki | last post: by
5 posts views Thread by Hartmut Sbosny | last post: by
11 posts views Thread by Niels Dekker - no reply address | last post: by
2 posts views Thread by Greg Buchholz | last post: by
5 posts views Thread by Wayne Shu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.