Specialization problem

Discussion in 'C++' started by Jon Slaughter, Sep 15, 2005.

  1. 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))
    Jon Slaughter, Sep 15, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CoolPint
    Replies:
    3
    Views:
    397
    Sergei Zyablov
    Nov 21, 2003
  2. Adam
    Replies:
    3
    Views:
    478
    Victor Bazarov
    Nov 2, 2004
  3. Alex@L
    Replies:
    6
    Views:
    469
    Mike Wahler
    Jan 20, 2005
  4. Marco Jez
    Replies:
    3
    Views:
    3,047
    Marco Jez
    Mar 27, 2005
  5. Joseph Turian
    Replies:
    2
    Views:
    454
Loading...

Share This Page