Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: error: enclosing class templates are not explicitly specialized

53 views
Skip to first unread message
Message has been deleted

Thomas Maeder

unread,
Aug 31, 2009, 11:08:21 AM8/31/09
to
pio...@unet.univie.ac.at (Piotr Sawuk) writes:

> gcc-version 4.1.2
>
> error: explicit specialization in non-namespace scope 'class _BRInsertSort_HelperClass<V, Less>'
> error: enclosing class templates are not explicitly specialized

What line does the error refer to?

And please reduce your code to the bare minimum (no more, no less)
that still causes g++ to produce the error message.


> what does this error mean? how can I fix it? could someone
> please test it with other compilers/versions? does my program
> actually obey the c++ standard?

No. But none of the obvious errors (which I mention below) seems to be
related to your problem.


> my source-code is:
>
> #include <functional>
>
> template <class V, class Less>
> class _BRInsertSort_HelperClass{

Names containing __ or starting with _[A-Z] are reserved to the C++
implementation. We mere users must not declare them.


> void main()

The return type of the main() function has to be int.

Message has been deleted

Thomas Maeder

unread,
Sep 9, 2009, 3:34:50 AM9/9/09
to
pio...@unet.univie.ac.at (Piotr Sawuk) writes:

> In article <87bplwt...@madbox3.site>,


> Thomas Maeder <mae...@glue.ch> writes:
>
>> What line does the error refer to?
>>
>> And please reduce your code to the bare minimum (no more, no less)
>> that still causes g++ to produce the error message.
>

> template <class V>
> class B{
>
> template<int i>
> inline void f(V v) {}
> //error in next 2 lines
> template <>
> void f<3>(V v) {}
> };
>
> g++ output:
> delme.cpp:7: error: explicit specialization in non-namespace scope 'class B<V>'
> delme.cpp:7: error: enclosing class templates are not explicitly specialized
> delme.cpp:8: error: 'f' is not a function template
> delme.cpp:8: error: invalid function declaration

These messages mean that

1. the correct place for specializing a member function template is
*outside* the class definition, in the namespace that the class
belongs to

2. the class template that the member function template belongs to
must be explicitly specialized in that specialization as well;
i.e. you can't provide an explicit specialization of f for 3 for all
types V


E.g. this is a correct explicit specialization of f:

template <class V>
class B
{
template<int i>
inline void f(V v) {}
};

template <>
template <>
void B<unsigned int>::f<3>(unsigned int i) {}

0 new messages