Template partial specialization

Discussion in 'C++' started by TT \(Tom Tempelaere\), Jan 12, 2004.

  1. Comeau compiler complains (too few arguments for class template "B") at line
    ***

    #include <memory>

    template<typename T, size_t n>
    struct A {};

    template<typename T, size_t n>
    struct B;

    template<typename T>
    struct B<T,2> {};

    int main()
    {
    A<int,2> a;
    B<float> b; // ***
    }

    What am I doing wrong?
    --
    Tom Tempelaere
    TT \(Tom Tempelaere\), Jan 12, 2004
    #1
    1. Advertising

  2. TT (Tom Tempelaere) wrote in
    news:ixxMb.8679$-ops.be:

    > Comeau compiler complains (too few arguments for class template "B")
    > at line ***
    >
    > #include <memory>
    >
    > template<typename T, size_t n>
    > struct A {};
    >


    Add a default here if that is what you want.

    template<typename T, size_t n = 3 >


    > template<typename T, size_t n>
    > struct B;
    >
    > template<typename T>
    > struct B<T,2> {};
    >
    > int main()
    > {
    > A<int,2> a;
    > B<float> b; // ***
    > }
    >
    > What am I doing wrong?


    Your declaring a default, so you can't use a default.

    Either add a sutible default or change line *** to

    B< float, 3 > b;

    HTH.

    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
    Rob Williscroft, Jan 12, 2004
    #2
    1. Advertising

  3. "Rob Williscroft" <> wrote in message
    news:Xns946E8EBB3F680ukcoREMOVEfreenetrtw@195.129.110.200...
    > TT (Tom Tempelaere) wrote in
    > news:ixxMb.8679$-ops.be:
    >
    > > Comeau compiler complains (too few arguments for class template "B")
    > > at line ***
    > >
    > > #include <memory>
    > >
    > > template<typename T, size_t n>
    > > struct A {};
    > >

    >
    > Add a default here if that is what you want.
    >
    > template<typename T, size_t n = 3 >


    That is _not_ what I want to do.

    > > template<typename T, size_t n>
    > > struct B;
    > >
    > > template<typename T>
    > > struct B<T,2> {};
    > >
    > > int main()
    > > {
    > > A<int,2> a;
    > > B<float> b; // ***
    > > }
    > >
    > > What am I doing wrong?

    >
    > Your declaring a default, so you can't use a default.


    I am not declaring a default, I'm partially specializing a template class.
    That has nothing to do with defaults!

    > Either add a sutible default or change line *** to
    >
    > B< float, 3 > b;


    That would make partial specialization totally unusable!

    Do you actually know what partial specialization of a template class is?

    > HTH.
    >
    > Rob.


    Tom.
    TT \(Tom Tempelaere\), Jan 12, 2004
    #3
  4. TT (Tom Tempelaere) wrote in
    news:_jyMb.8737$-ops.be:

    > "Rob Williscroft" <> wrote in message
    > news:Xns946E8EBB3F680ukcoREMOVEfreenetrtw@195.129.110.200...
    >> TT (Tom Tempelaere) wrote in
    >> news:ixxMb.8679$-ops.be:
    >>


    [snip]

    >> Add a default here if that is what you want.
    >>
    >> template<typename T, size_t n = 3 >

    >
    > That is _not_ what I want to do.


    Actually when you combine the default with the specialization, it
    probably is, but you didn't say what you wanted to do.

    >
    >> > template<typename T, size_t n>
    >> > struct B;
    >> >
    >> > template<typename T>
    >> > struct B<T,2> {};
    >> >
    >> > int main()
    >> > {
    >> > A<int,2> a;
    >> > B<float> b; // ***
    >> > }
    >> >
    >> > What am I doing wrong?

    >>
    >> Your declaring a default, so you can't use a default.

    >


    Whoops missed a *not* in the above, It should have been:

    Your not declaring a default, so you can't use a default.

    > I am not declaring a default, I'm partially specializing a template
    > class. That has nothing to do with defaults!


    Yes you are, but then you try to use the class as if you had
    given it a default for its second paramiter.

    >
    >> Either add a sutible default or change line *** to
    >>
    >> B< float, 3 > b;

    >
    > That would make partial specialization totally unusable!


    You seem to be confused about what specialization does.

    There can be only one class or class-template named B, if its
    a class-template say B< typename, size_t > then it takes 2
    arguments, specialization *isn't* overloading.

    From your code above:

    B< int, 1 > b1; // will instantiate the the unspecialized template.

    B< int, 2 > b2; // will instantiate the specialization.

    >
    > Do you actually know what partial specialization of a template class
    > is?


    :) Yes *I* do.

    >
    >> HTH.
    >>


    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
    Rob Williscroft, Jan 12, 2004
    #4
  5. "Rob Williscroft" <> wrote in message
    news:Xns946E9DA786423ukcoREMOVEfreenetrtw@195.129.110.205...
    > TT (Tom Tempelaere) wrote in
    > news:_jyMb.8737$-ops.be:
    >
    > > "Rob Williscroft" <> wrote in message
    > > news:Xns946E8EBB3F680ukcoREMOVEfreenetrtw@195.129.110.200...
    > >> TT (Tom Tempelaere) wrote in
    > >> news:ixxMb.8679$-ops.be:
    > >>

    >
    > [snip]
    >
    > >> Add a default here if that is what you want.
    > >>
    > >> template<typename T, size_t n = 3 >

    > >
    > > That is _not_ what I want to do.

    >
    > Actually when you combine the default with the specialization, it
    > probably is, but you didn't say what you wanted to do.
    >
    > >
    > >> > template<typename T, size_t n>
    > >> > struct B;
    > >> >
    > >> > template<typename T>
    > >> > struct B<T,2> {};
    > >> >
    > >> > int main()
    > >> > {
    > >> > A<int,2> a;
    > >> > B<float> b; // ***
    > >> > }
    > >> >
    > >> > What am I doing wrong?
    > >>
    > >> Your declaring a default, so you can't use a default.

    > >

    >
    > Whoops missed a *not* in the above, It should have been:
    >
    > Your not declaring a default, so you can't use a default.
    >
    > > I am not declaring a default, I'm partially specializing a template
    > > class. That has nothing to do with defaults!

    >
    > Yes you are, but then you try to use the class as if you had
    > given it a default for its second paramiter.
    >
    > >
    > >> Either add a sutible default or change line *** to
    > >>
    > >> B< float, 3 > b;

    > >
    > > That would make partial specialization totally unusable!

    >
    > You seem to be confused about what specialization does.
    >
    > There can be only one class or class-template named B, if its
    > a class-template say B< typename, size_t > then it takes 2
    > arguments, specialization *isn't* overloading.
    >
    > From your code above:
    >
    > B< int, 1 > b1; // will instantiate the the unspecialized template.
    >
    > B< int, 2 > b2; // will instantiate the specialization.
    >
    > >
    > > Do you actually know what partial specialization of a template class
    > > is?

    >
    > :) Yes *I* do.


    :)) I think I got it all screwed up. You are correct.

    I'm sorry for questioning you.

    Thanks,
    Tom.

    > >
    > >> HTH.
    > >>

    >
    > Rob.
    > --
    > http://www.victim-prime.dsl.pipex.com/
    TT \(Tom Tempelaere\), Jan 12, 2004
    #5
    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. Chandra Shekhar Kumar

    template partial specialization

    Chandra Shekhar Kumar, Jun 24, 2003, in forum: C++
    Replies:
    17
    Views:
    3,027
    tom_usenet
    Jun 25, 2003
  2. Joseph Turian
    Replies:
    2
    Views:
    463
  3. toton
    Replies:
    1
    Views:
    610
  4. vj
    Replies:
    1
    Views:
    481
  5. Hizo
    Replies:
    17
    Views:
    680
    itaj sherman
    Mar 7, 2011
Loading...

Share This Page