473,837 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class Template Member Class Template Specialisaton Query

Hello!

I have a query regarding explicit specialisation of class templates
which are themselves members of class templates.

Here's what I want to do:

template< class T > struct pink {

template< class U > struct floyd;

};

template< class T > template< class U >
struct pink<T>::floyd {

pink seamus();

U eugene();

};

/* Here's the specialisation I'm wondering
about (with line numbers given in
comments on the left): */

template< class T >
/*19*/ struct pink<T>::floyd< int> {

/*21*/ pink seamus();

float eugene();

};

Comeau's online compiler does fine with that :-) but GCC 3.2.3 does not
:-( Instead, g++ says:

[source file]:19: template parameters not used in partial
specialization:
[source file]:19: `T'
[source file]:21: syntax error before `(' token

However, I can get it to (sort of) work if I change the specialisation
definition to:

template< class T >
struct pink<T>::floyd< int> {

pink<T> seamus();

float eugene();

};

though it still warns about T being an unused template parameter.

I'd just like to confirm my suspicion that GCC 3.2.3 is incorrect on
this, and that the original version of my code is correct :-)

Thank you!

Simon

Jul 19 '05 #1
2 2416
Simon G Best wrote:
Hello!

I have a query regarding explicit specialisation of class templates
which are themselves members of class templates.

Here's what I want to do:

template< class T > struct pink {

template< class U > struct floyd;

};

template< class T > template< class U >
struct pink<T>::floyd {

pink seamus();

U eugene();

};

/* Here's the specialisation I'm wondering
about (with line numbers given in
comments on the left): */

template< class T >
/*19*/ struct pink<T>::floyd< int> {

/*21*/ pink seamus();

float eugene();

};
You could theoretically do it with 2 non nested structs.

template<class T, class U> struct floyd;

template<class T> struct pink;

template<class T, class U>
struct floyd {

pink<T> seamus();
U eugene();
};

template<class T>
struct floyd<T,int> {

pink<T> seamus();
float eugene();
};

Comeau's online compiler does fine with that :-) but GCC 3.2.3 does not
:-( Instead, g++ says:

[source file]:19: template parameters not used in partial
specialization:
[source file]:19: `T'
[source file]:21: syntax error before `(' token

However, I can get it to (sort of) work if I change the specialisation
definition to:

template< class T >
struct pink<T>::floyd< int> {

pink<T> seamus();

float eugene();

};

though it still warns about T being an unused template parameter.
I suspect this is a problem with g++. File a bug with gcc, they're
usually very responsive.

I'd just like to confirm my suspicion that GCC 3.2.3 is incorrect on
this, and that the original version of my code is correct :-)
I tried your original version on gcc 3.3.1, you could aloso try a 3.4
devel version of gcc, they're trying to fix things like this.


Jul 19 '05 #2
Gianni Mariani wrote:

You could theoretically do it with 2 non nested structs.
Yeah, it looks like that's what I'll have to do (though it looks untidy,
as floyd really belongs to pink) :-(

(Or I could do interesting things behind the scenes with templates
outside the containing template, and then define the member template in
terms of those exterior templates. But I don't like 'clever' solutions
like that - I prefer to work /with/ the language, rather than try to
overcome it.)

[Example of two nonnested templates snipped.]
I suspect this is a problem with g++. File a bug with gcc, they're
usually very responsive.
Well, I've since learned (from johnchx in comp.lang.c++.m oderated) that
the standard actually forbids what I was trying to do (14.7.3.18 says
that it isn't allowed). To explicitly specialise a member class
template, the enclosing class templates also need to be specialised :-(

GCC 3.2.3 is actually correctly reporting the error when I try to do it
the obvious way:

template< class T > template<>
struct pink<T>::floyd< int> { /* etc... */ };

It reports the lack of specialisation of the enclosing class, which is
consistent with the standard after all (and so my faith in GCC is
restored :-) ).
I tried your original version on gcc 3.3.1, you could aloso try a 3.4
devel version of gcc, they're trying to fix things like this.


Thanks :-) but it seems I'm going to need to redesign things instead :-(

Simon

Jul 19 '05 #3

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

Similar topics

7
2141
by: Lionel B | last post by:
Greetings. The following code compiles ok and does what I'd expect it to do: ---------- START CODE ---------- // test.cpp
9
1970
by: Ian | last post by:
Can it be done? If so, what's the syntax. For example a full specialisation, template <typename T> struct X { template <typename C> void foo( C a ) {} };
9
8259
by: tropostropos | last post by:
On Solaris, using the Sun compiler, I get annoying warnings from the following code. The problem is that I am passing a C++ member function pointer to the C library function qsort. Is there a solution? Declaring the function extern "C" fails, because linkage declarations must be made at file scope. #include <stdlib.h> //for qsort template <class T> class Sorter
4
3339
by: Joseph Turian | last post by:
Hi, What is the correct syntax to get the bar<T>::f<int, unsigned>() function to compile in the following fragment? Thanks, Joseph class foo {
2
2321
by: pookiebearbottom | last post by:
Just trying to learn some things about templates. Was wondering how boost::tupple really works, but the headers were a bit confusing to me. I know you get do something like the following, just want to know how it works with the overloading of get<>(). boost::tupple<int,doubletup(1,2.0); double d=tup.get<2>(); // equal 2.0 // simple set up,
1
2301
by: Frederiek | last post by:
Hi, When modifying a data member in a class declaration, the static keyword specifies that one copy of the member is shared by all instances of the class. Does that mean that the address of the data member is the same for every instance of that class? I would expect so, but I noticed something that makes me doubt a little.
3
2927
by: toton | last post by:
Hi, I want to specialize template member function of a template class . It is creating some syntax problem .... Can anyone say how to do it ? The class is something like this template<typename T,typename Alloc = std::allocator<T class CircularBuffer4 { public: typedef typename CircularBuffer<T,Alloc>::size_type
4
8002
by: zfareed | last post by:
#include <iostream> #include <fstream> using namespace std; template<class ItemType> class SortedList { private:
2
7709
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
0
9843
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10881
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10575
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9406
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7807
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7004
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5850
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4475
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3126
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.