472,989 Members | 3,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

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 2159
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Istvan Buki | last post by:
Dear C++ gurus, I'm having some problems inserting some template classes into containers. I'm looking for ideas, suggestions,... on how to achieve this but first let me explain my problem....
13
by: Walt Karas | last post by:
The following gives an error in the declaration of the member function x() of the class template Tpl, compiliing with a recent version of GCC under Solaris: class A { }; class B { }; ...
5
by: Hartmut Sbosny | last post by:
Hello NG, I have a ordinary class `Base' with two functions `void foo()' and `void any()': class Base { public: Base() {} void foo() {} void any() {}
3
by: Chris | last post by:
I am having a very strange problem involving virtual functions in template classes. First of all, here is an extremely simplified structure of the two classes I am having problems with. ...
11
by: Niels Dekker - no reply address | last post by:
The following attempt to pass my template "Base" as a template template argument was rejected by Microsoft VC++ 8.0 (2005), while it still works on VC++ 7.1 (2003). Is it correct C++? And is...
2
by: Greg Buchholz | last post by:
/* I've been experimenting with some generic/polytypic programs, and I've stumbled on to a problem that I can't quite figure out. In the program below, I'm trying to define a generic version of...
2
by: pagekb | last post by:
Hello, I'm having some difficulty compiling template classes as containers for other template objects. Specifically, I have a hierarchy of template classes that contain each other. Template...
5
by: Wayne Shu | last post by:
Hi, guys I am reading Vandevoorde and Josuttis 's "C++ Template The Complete Guide" these days. When I read the chapter 15: Traits and Policy classes. I copy the code in 15.2.2 that use to...
2
by: aitrob | last post by:
Hi, I have a problem concerning templates/inheritance. I have a code that compiles fine with g++ 4.0.1 (Apple version), but gives a lot of errors with Intel C++ 10.1 (Mac OS X). I'm not sure if...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.