468,272 Members | 2,045 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

Specialization problem

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))


Sep 15 '05 #1
0 1274

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by Paul MG | last post: by
9 posts views Thread by Philip Lawatsch | last post: by
8 posts views Thread by Agent Mulder | last post: by
5 posts views Thread by __PPS__ | last post: by
19 posts views Thread by Nicolas Fleury | last post: by
4 posts views Thread by Michael Sparks | last post: by
3 posts views Thread by Scott Frazer | last post: by
2 posts views Thread by Yang Zhang | last post: by
6 posts views Thread by abir | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.