Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Template partial specialization

Reply
Thread Tools

Template partial specialization

 
 
TT \(Tom Tempelaere\)
Guest
Posts: n/a
 
      01-12-2004
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


 
Reply With Quote
 
 
 
 
Rob Williscroft
Guest
Posts: n/a
 
      01-12-2004
TT (Tom Tempelaere) wrote in
news:ixxMb.8679$(E-Mail Removed)-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/
 
Reply With Quote
 
 
 
 
TT \(Tom Tempelaere\)
Guest
Posts: n/a
 
      01-12-2004
"Rob Williscroft" <(E-Mail Removed)> wrote in message
news:Xns946E8EBB3F680ukcoREMOVEfreenetrtw@195.129. 110.200...
> TT (Tom Tempelaere) wrote in
> news:ixxMb.8679$(E-Mail Removed)-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.


 
Reply With Quote
 
Rob Williscroft
Guest
Posts: n/a
 
      01-12-2004
TT (Tom Tempelaere) wrote in
news:_jyMb.8737$(E-Mail Removed)-ops.be:

> "Rob Williscroft" <(E-Mail Removed)> wrote in message
> news:Xns946E8EBB3F680ukcoREMOVEfreenetrtw@195.129. 110.200...
>> TT (Tom Tempelaere) wrote in
>> news:ixxMb.8679$(E-Mail Removed)-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/
 
Reply With Quote
 
TT \(Tom Tempelaere\)
Guest
Posts: n/a
 
      01-12-2004
"Rob Williscroft" <(E-Mail Removed)> wrote in message
news:Xns946E9DA786423ukcoREMOVEfreenetrtw@195.129. 110.205...
> TT (Tom Tempelaere) wrote in
> news:_jyMb.8737$(E-Mail Removed)-ops.be:
>
> > "Rob Williscroft" <(E-Mail Removed)> wrote in message
> > news:Xns946E8EBB3F680ukcoREMOVEfreenetrtw@195.129. 110.200...
> >> TT (Tom Tempelaere) wrote in
> >> news:ixxMb.8679$(E-Mail Removed)-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/



 
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 template partial specialization Hizo C++ 17 03-07-2011 08:09 AM
how to do partial specialization template for non member method template vj C++ 1 12-20-2010 11:57 AM
syntax problem for partial template specialization for a template class. toton C++ 1 12-28-2006 04:08 PM
template specialization overriding non-specialization? Joseph Turian C++ 2 04-16-2006 02:46 PM
template partial specialization Chandra Shekhar Kumar C++ 17 06-25-2003 03:35 PM



Advertisments