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 2 2385
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.
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++.moderated) 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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
|
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 ) {}
};
|
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...
|
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 {
|
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...
|
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...
|
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...
|
by: zfareed |
last post by:
#include <iostream>
#include <fstream>
using namespace std;
template<class ItemType>
class SortedList
{
private:
|
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:
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
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...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |