473,320 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Template partial specialization

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
Jul 22 '05 #1
4 1931
TT (Tom Tempelaere) wrote in
news:ix********************@phobos.telenet-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/
Jul 22 '05 #2
"Rob Williscroft" <rt*@freenet.REMOVE.co.uk> wrote in message
news:Xn**********************************@195.129. 110.200...
TT (Tom Tempelaere) wrote in
news:ix********************@phobos.telenet-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.
Jul 22 '05 #3
TT (Tom Tempelaere) wrote in
news:_j********************@phobos.telenet-ops.be:
"Rob Williscroft" <rt*@freenet.REMOVE.co.uk> wrote in message
news:Xn**********************************@195.129. 110.200...
TT (Tom Tempelaere) wrote in
news:ix********************@phobos.telenet-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/
Jul 22 '05 #4
"Rob Williscroft" <rt*@freenet.REMOVE.co.uk> wrote in message
news:Xn**********************************@195.129. 110.205...
TT (Tom Tempelaere) wrote in
news:_j********************@phobos.telenet-ops.be:
"Rob Williscroft" <rt*@freenet.REMOVE.co.uk> wrote in message
news:Xn**********************************@195.129. 110.200...
TT (Tom Tempelaere) wrote in
news:ix********************@phobos.telenet-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/

Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section...
1
by: BekTek | last post by:
I'm still confused about the template partial specialization which is used in many libraries.. due to lack of introduction for beginner.. Could you tell me about that in short? Thanks in...
1
by: Kai-Uwe Bux | last post by:
Hi folks, I would like to know which clause of the standard rules out this: template < typename eval > struct recursive_template { typedef typename eval::enum_type Enum;
2
by: lhr_cool_guy | last post by:
C++ doesn't allow partial specialization of function templates. I want to know why this is so? Is the concept of function template partial specialization not well defined? I have a case where I...
7
by: melfar | last post by:
Hello group, Consider such a class hierachy: template<typename Type> class SomeConcreteUsefulClass {} template<typename Type, typename SomeUsefulClass> class BaseClass {}
7
by: er | last post by:
hi, could someone please help with this code? template<unsigned int N,unsigned int M> class A{ public: A(); };
4
by: George2 | last post by:
Hello everyone, About Template Partial Specialization, http://www.cprogramming.com/tutorial/template_specialization.html sometimes in real case like below, ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.