Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Specialization problem

Reply
Thread Tools

Specialization problem

 
 
Jon Slaughter
Guest
Posts: n/a
 
      09-15-2005
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))






 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
template specialization overriding non-specialization? Joseph Turian C++ 2 04-16-2006 02:46 PM
problem in static function template specialization Marco Jez C++ 3 03-27-2005 10:13 PM
Problem with Partial Template Specialization and Borland C++ Builder Alex@L C++ 6 01-20-2005 08:34 PM
template specialization problem, but only with char* Adam C++ 3 11-02-2004 11:52 PM
Problem with template specialization CoolPint C++ 3 11-21-2003 10:42 AM



Advertisments