473,769 Members | 1,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

template inherits from template passing its argument is not legal c++ ?

Dear group,

I tested this code in a 4.x gcc, MSVC 8.0, 7.1 and comeau in strict and
relaxed mode.
It compiles in MSVC and relaxed comeau, but fails in gcc 4.x and strict
comeau

It seems it is not possible to derive from a template class and pass it
an argument that is a template parameter itself in the derived class.
This would break a lot of my code.
But I could imagine that this is just not the exactly right way to code
it. Does anyone have any hints on this?
Does anyone know, wether it is possible to tell the gcc to compile in
something similar to the comeau relaxed mode?
And finally, can anyone tell, what the standard says? I don't have the
standard unfortunately.

Thanks for your help
Ingo

// main.cpp

template< typename dataT >
struct A
{
typedef dataT DataT;

DataT* _pCol;
int _n;
};

template< typename T >
struct B : A< int >
{
typedef DataT CanISeeIt;

void func( )
{
_pCol;
_n;
}

};

template< typename T >
struct C : A< T >
{
typedef DataT CanISeeIt;

void func( )
{
_pCol;
_n;
}
};

int main( ){}

Jun 5 '06 #1
4 1782
nutty wrote:
Dear group,

I tested this code in a 4.x gcc, MSVC 8.0, 7.1 and comeau in strict and
relaxed mode.
It compiles in MSVC and relaxed comeau, but fails in gcc 4.x and strict
comeau

It seems it is not possible to derive from a template class and pass it
an argument that is a template parameter itself in the derived class.
This would break a lot of my code.
But I could imagine that this is just not the exactly right way to code
it. Does anyone have any hints on this?
Does anyone know, wether it is possible to tell the gcc to compile in
something similar to the comeau relaxed mode?
And finally, can anyone tell, what the standard says? I don't have the
standard unfortunately.

Thanks for your help
Ingo

// main.cpp

template< typename dataT >
struct A
{
typedef dataT DataT;

DataT* _pCol;
int _n;
};

template< typename T >
struct B : A< int >
{
typedef DataT CanISeeIt;

void func( )
{
_pCol;
_n;
}

};

template< typename T >
struct C : A< T >
{
typedef DataT CanISeeIt;

void func( )
{
_pCol;
_n;
}
};

int main( ){}


Just change your C<> class to the correct way:

template< typename T >
struct C : A< T >
{
typedef typename A<T>::DataT CanISeeIt;

void func( )
{
this->_pCol; // or A<T>::_pCol;
this->_n; // or A<T>::_n;
}
};

See this FAQ and the one following:

http://www.parashift.com/c++-faq-lit...html#faq-35.18

Cheers! --M

Jun 5 '06 #2
See this FAQ and the one following:

http://www.parashift.com/c++-faq-lit...html#faq-35.18

Wow, thank you very much for this quick and excellent reply.

What I learned from this, is to re-read the faq each time before I post
silly questions.

However, I now have a rather academic question.
Why is the standard like this? It seems a little inconsistent to me and
MSVC seems to indicate that it is possible differently. Is there a
catch? Is there a good reason for this?

thank you
Ingo

Jun 5 '06 #3
nutty wrote:
See this FAQ and the one following:

http://www.parashift.com/c++-faq-lit...html#faq-35.18

Wow, thank you very much for this quick and excellent reply.

What I learned from this, is to re-read the faq each time before I post
silly questions.

However, I now have a rather academic question.
Why is the standard like this? It seems a little inconsistent to me and
MSVC seems to indicate that it is possible differently. Is there a
catch? Is there a good reason for this?


See if #2 and #7 - #10 in these template FAQs clear it up:

http://womble.decadentplace.org.uk/c...plate-faq.html

Cheers! --M

Jun 5 '06 #4
> > catch? Is there a good reason for this?

See if #2 and #7 - #10 in these template FAQs clear it up:

http://womble.decadentplace.org.uk/c...plate-faq.html

thank you, yes, this cleared it up for me.

Jun 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
6865
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section 18.3.1, 'Iseq'). I want the version for containers that he gives, but also to provide a specialization for construction from a pair<It,It> (eg because that is returned by equal_range()).
7
6191
by: wogston | last post by:
A) template <typename scalar, int size> struct basevector { enum { size = size }; scalar v; }; B)
4
1747
by: Dave | last post by:
Hello all, I hope the context to my problem shown below is adequate but not overwhelming. I tried to keep it minimal. At the line indicated (in comment form) in the source below, the following error is occurring (VC++ 7.1): error C2663: 'std::_Tree<_Traits>::find' : 2 overloads have no legal conversion for 'this' pointer
6
9269
by: Brian Ross | last post by:
Hi, I am trying to do something similar to the following: int Func1(int x, int y); double Func2(double x, double y); template <typename FuncT> // <- What would go here class CObjectT {
14
2905
by: Bart Samwel | last post by:
Hi everybody, I would really like some help explaining this apparent discrepancy, because I really don't get it. Here is the snippet: void foo(int&); void foo(int const&); template<typename T>
6
8262
by: bob_jenkins | last post by:
{ const void *p; (void)memset((void *)p, ' ', (size_t)10); } Should this call to memset() be legal? Memset is of type void *memset(void *, unsigned char, size_t) Also, (void *) is the generic pointer type. My real question is, is (void *) such a generic pointer type that it
3
1338
by: Serge Skorokhodov (216716244) | last post by:
Hi, I just seeking advice. Some background information first because I've run into issues that seems pretty obscure to me:( Quick search through KB yields next to nothing. Simplified samples work OK as well, the problems appear in rather bulky code:( I'm trying to implement some signal processing algorithm using
6
2811
by: rincewind | last post by:
Hi, can anybody summarise all options for partial template specialization, for all kind of parameters (type, nontype, template)? I *think* I understand options for partial specialization on type parameters - in place of a template argument one can construct arbitrary valid C++ type declaration, more or less like in "typedef" statement. What about nontype parameters? Am I right that you cannot partially
2
6645
by: Clyde | last post by:
Hi, what i'm trying to do is: /////////////// Code Start template <class TType, int* p = 0> class Template { public:
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10045
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
9994
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
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7408
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
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
5298
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...
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.