473,699 Members | 2,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>::Typ e // this is acceptable
{};

Is this expected behavior?
Jun 14 '06 #1
2 2201
"RitualDave " <Ri********@dis cussions.micros oft.com> wrote in message
news:9A******** *************** ***********@mic rosoft.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>::Typ e // 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********@dis cussions.micros oft.com> wrote in message
news:9A******** *************** ***********@mic rosoft.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>::Typ e // 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
1847
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. Everything starts with a simple template class like the one below. In this example class A has two template parameters but that number can be different. template < typename T, typename U > class A
13
2819
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 { }; template <typename Base> class Tpl : protected Base {
5
1639
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
3936
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. template<class Type> class base { public: base& operator/=(const base&); Type *image;
11
3092
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 there a workaround? template <typename T> class Base { }; template <typename U, template <typename> class TempTemp> class Derived;
2
1975
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 "transform" which works not only on lists, but lists of list, lists of lists of lists, etc. I'm calling it "fmap" and it passes around actual lists instead of iterators (for now). In order to get it to work, I thought I'd have one templated...
2
3339
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 class B has an instance of template class A, which has some base type T (usually int or double). However, the base type T is important to calculations in B, so I would like to obtain access to the type for further variable declaration within B. ...
5
2534
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 determining the class type. The code is below:
2
2599
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 I'm doing something wrong and g++ just doesn't notice, or if the people at Intel are doing something weird... What am I trying to do? I'm trying to implement a template class that inherits from the Blitz++ array library #include <blitz/array.h>...
0
9173
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9033
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8911
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5872
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2345
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.