Specialization problem

J

Jon Slaughter

I'm having a big problem(its probably simple but I just can't seem to figure
it out).

I have a Node template:

template <unsigned int I, unsigned int J, typename T>
struct Node
{
enum {i = I};
enum {j = J};
typedef T Class;
};


Now I have a template class I'm trying to pass a Node to

template <class A>
struct T
{
.....
};

and I would do something like T<Node<3,2,someclass>> B;

Now what I want to do is specialize T so that it if A is of Node type then
it will inherit Node::Class i.e.

template <class A>
struct T : public A::Class
{
}


which works fine... but this isn't specializing T. I've tried to do

template <class A>
struct T
{
};

template <class A>
struct T<Node> : public A::Class
{

};

but that doesn't work... I've tried to use template template parameters and
a whole lot of other crap but nothing works ;/

I need to specialize T because in reality I will be having a variable number
of Nodes... hmm.. I just can't figure out why the above won't work(ofcourse
its cause I'm weak at templates but thats besides the point ;)).

To me, the way I see it is that when I do

T<Node<1,2,someclass>> the compiler will find the specialization of T that
is being passed a note type(or does it also try to match the exact type such
as 1,2,class?) and then everything should work...

Just not sure what to do since I get some errors that don't make any sense
to me like:

'Node' : unspecialized class template can't be used as a template argument
for template parameter 'A', expected a real type.


Any ideas how to do this?

Thanks, Jon

BTW, what I'm eventually going to try to do is have a templatized recursive
class structure where you can "attach" a class to any of the "nodes" that
are generated.

So one might do something like

T<Node<5,3, classC>, Node<3,3, classA>, ...>

the first entry specifies the general class attached to all the notes and
the "depth" of the notes(i.e. 5,3) and the other parameters specify
"attaching" notes at those points. So in this case all notes will have
classC except node 3,3 which has classA.

Hopefully it won't be to hard to do this... I think once I fix this problem
the rest isn't going to be as hard(as I've got the recursion down and I
think I can figure out the variable templates using similar structures as
the TypeList(or might even use TypeList to hold them))
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top