using templates in templates

J

John Harrison

Torsten Curdt said:
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
 
T

Torsten Curdt

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

This does not seem to work - but why?
 
J

Jakob Bieling

Torsten Curdt said:
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
 
G

Greg P.

Jakob Bieling said:
template <template <class T, class U> class TYPE, class ELEMENT>
class MyClass : public TYPE <ELEMENT,ELEMENT>
God what a headache! Generalizing the generalized! =/
 
J

Jakob Bieling

Torsten Curdt said:
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
 
T

Torsten Curdt

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 :(
 
T

Torsten Curdt

Jakob said:
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 :-/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

templates?? 2
Templates and g++ 4
Specializing Perfect Forwarding Templates? 20
templates 10
Variadic templates std::tuple 2
Why export templates would be useful 33
Templates 4 a Nu-B 1
Specialized Templates 3

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top