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