By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 833 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

using templates in templates

P: n/a
template<class TYPE, class ELEMENT>
class MyClass : public TYPE<ELEMENT,ELEMENT>
{
};

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

Jul 19 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a

"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

P: n/a
"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

P: n/a
"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

P: n/a
"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

P: n/a
> 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

P: n/a
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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.