By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,708 Members | 1,456 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,708 IT Pros & Developers. It's quick & easy.

template template parameter used as base class of ref class error

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
"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

P: n/a

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.