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? 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>
{};
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> {}; This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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
{
|
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() {}
|
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;
|
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;
| |
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...
|
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. ...
|
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:
|
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>...
|
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...
|
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...
| |
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,...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |