Template partial specialization

  • Thread starter TT \(Tom Tempelaere\)
  • Start date
T

TT \(Tom Tempelaere\)

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

Rob Williscroft

TT (Tom Tempelaere) wrote in
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>
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.
 
T

TT \(Tom Tempelaere\)

Rob Williscroft said:
TT (Tom Tempelaere) wrote in


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

Rob Williscroft

TT (Tom Tempelaere) wrote in
Rob Williscroft said:
TT (Tom Tempelaere) wrote in
[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.

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.
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 said:
Do you actually know what partial specialization of a template class
is?

:) Yes *I* do.

Rob.
 
T

TT \(Tom Tempelaere\)

Rob Williscroft said:
TT (Tom Tempelaere) wrote in
Rob Williscroft said:
TT (Tom Tempelaere) wrote in
[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.

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.
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 said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top