473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

using templates in templates

template<class TYPE, class ELEMENT>
class MyClass : public TYPE<ELEMENT,ELEMENT>
{
};

This does not seem to work - but why?
--
Torsten

Jul 19 '05 #1
8 3298

"Torsten Curdt" <tc***********@web.de> wrote in message
news:bg************@ID-37954.news.uni-berlin.de...
template<class TYPE, class ELEMENT>
class MyClass : public TYPE<ELEMENT,ELEMENT>
{
};

This does not seem to work - but why?


Because it makes my head hurt?

john
Jul 19 '05 #2
"Torsten Curdt" <tc***********@web.de> wrote in message
news:bg************@ID-37954.news.uni-berlin.de...
template<class TYPE, class ELEMENT>
class MyClass : public TYPE<ELEMENT,ELEMENT>
{
};

This does not seem to work - but why?


You are using the wrong syntax. You need to specify that you want TYPE
to be a template class that takes two typename-parameters (or
class-parameters, it is the same thing), like this:

template <template <class T, class U> class TYPE, class ELEMENT>
class MyClass : public TYPE <ELEMENT,ELEMENT>
{
};

hth
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #3
"Jakob Bieling" <ne*****@gmy.net> wrote in message
news:bg*************@news.t-online.com...
"Torsten Curdt" <tc***********@web.de> wrote in message
news:bg************@ID-37954.news.uni-berlin.de...
template <template <class T, class U> class TYPE, class ELEMENT>
class MyClass : public TYPE <ELEMENT,ELEMENT>

God what a headache! Generalizing the generalized! =/
Jul 19 '05 #4
"Torsten Curdt" <tc***********@web.de> wrote in message
news:bg************@ID-37954.news.uni-berlin.de...
You are using the wrong syntax. You need to specify that you want TYPE to be a template class that takes two typename-parameters (or
class-parameters, it is the same thing), like this:

template <template <class T, class U> class TYPE, class ELEMENT>
class MyClass : public TYPE <ELEMENT,ELEMENT>
{
};
ok, but then I would need to use the template like this, right?

MyClass< Base<A,B> >


No, because a) Base<A,B> is no template class anymore (it is treated
like a regular class type) and b) MyClass takes two template parameters, but
you pass only one.
but because usually A == B I'd like to write

MyClass< Base, A >
If 'Base' is a template class and 'A' is a typename, then this is how
you would write it, yes.
but now I understand: "Base" is not a regular but a class
template - that's why, right?

Any way to work around this?


To work around what? You wrote, you would like to write "MyClass <Base,
A>" (and I assume 'Base' is a template class and 'A' is a typename), which
is exactly how you are supposed to write it.

hth
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #5
> To work around what? You wrote, you would like to write "MyClass <Base,
A>" (and I assume 'Base' is a template class and 'A' is a typename), which
is exactly how you are supposed to write it.


ok, thanks

too bad but the compiler doesn't like nested templates :(
--
Torsten

Jul 19 '05 #6
Torsten Curdt wrote:
To work around what? You wrote, you would like to write "MyClass
<Base,
A>" (and I assume 'Base' is a template class and 'A' is a typename),
which is exactly how you are supposed to write it.
ok, thanks

too bad but the compiler doesn't like nested templates :(

gcc does
--
Torsten


Jul 19 '05 #7
"Torsten Curdt" <tc***********@web.de> wrote in message
news:bg************@ID-37954.news.uni-berlin.de...
To work around what? You wrote, you would like to write "MyClass <Base, A>" (and I assume 'Base' is a template class and 'A' is a typename), which is exactly how you are supposed to write it.


ok, thanks

too bad but the compiler doesn't like nested templates :(

Which one are you using? VC++ 7.1 supports them.
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #8
Jakob Bieling wrote:
"Torsten Curdt" <tc***********@web.de> wrote in message
news:bg************@ID-37954.news.uni-berlin.de...
To work around what? You wrote, you would like to write "MyClass
<Base,
A>" (and I assume 'Base' is a template class and 'A' is a typename),
which
is exactly how you are supposed to write it.


ok, thanks

too bad but the compiler doesn't like nested templates :(


Which one are you using? VC++ 7.1 supports them.


eVC++ 4

In the help there is even an example of nested templates
but the compilers complains anyway :-/
--
Torsten

Jul 19 '05 #9

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

Similar topics

2
by: Sam | last post by:
I would like to store html templates in a database. By using perl I would like to retrive the template ask the user to fill the template and store the whole file is template + the user data in a...
2
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
3
by: Sandros | last post by:
Background: I'm collecting usability statistics for a group of applications. Each count has the following attributes: date, application, major heading, minor heading, count. My intent is to pull...
4
by: Pat Turner | last post by:
Hi, I have some XML like this: <family> <person name="bob"> <father ref="../../person" /> </person> <person name="charlie"> <child ref="../../person" />
16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
6
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows...
0
by: Piper707 | last post by:
I need help with using a general template which would process all tags other than the ones for which specific templates have been written. My XML looks like this: <ITEMS>...
1
by: oldgent | last post by:
I am having a problem installing the starter kits. I have reinstalled VS 2005, think that might be the problem. I then installed both 'Personal Website" and the "Club Website" starter kits. I...
28
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the...
6
by: John Larson | last post by:
Hi All, I am some information from INSPEC database records in XML to build a relational database of my own. I am currently trying to extract information by doing an XSLT transform of the XML...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...

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.