This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: explicit specialization in non-namespace scope
- From: Jonathan Wakely <cow at compsoc dot man dot ac dot uk>
- To: "Sujatha, Narayanan (IE10)" <Sujatha dot Narayanan at honeywell dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-help at gcc dot gnu dot org
- Date: Tue, 17 Jun 2003 10:29:34 +0100
- Subject: Re: explicit specialization in non-namespace scope
- References: <77ED2BF75D59D1439F90412CC5B1097480FE01@ie10-sahara.hiso.honeywell.com>
On Mon, Jun 16, 2003 at 11:20:54PM -0700, Sujatha, Narayanan (IE10) wrote:
>
> > I am using gcc 3.1 compiler for power pc. I am getting the following
> > errors if I specialize member templates.
Since this question hasn't been answered on gcc-help I'll do so here...
> > TEST_Stream_accessor.h:22: explicit specialization in non-namespace scope
> > `class TEST::Stream_accessor'
This error is telling you that the explicit specialisation is in a scope
where you are not allowed to make explicit specialisations.
In section temp.expl.spec the standard (*) says:
An explicit specialization shall be declared in the namespace of which
the template is a member, or, for member templates, in the namespace of
which the enclosing class or enclosing class template is a member.
So in this case the explicit specialisation must be in the namespace of
which Stream_accessor is a member.
You must move the specialisation outside the class declaration (and
qualify the function name with Stream_accessor::).
You must also remove the "static" storage class from the specialisation,
only the original declaration should be static, the function definition
and/or specialisations are always static if the declaration says so.
The corrected code is:
namespace TEST
{
class Stream_accessor
{
public:
Stream_accessor();
virtual ~Stream_accessor();
template < class Stream >
static void create_stream(Stream * * stream_ptr)
{}
};
template < >
void Stream_accessor::create_stream < std::istringstream > (std::istringstream * * stream_ptr)
{
* stream_ptr = new std::istringstream();
}
}
VC++ should not have compiled the original code.
hth,
jon
(*) This is actually from a draft of the standard, I don't have the final
version to hand. Caveat lector.
--
Some things have to be believed to be seen.
- Ralph Hodgson