pio...@unet.univie.ac.at (Piotr Sawuk) writes:

> In article <87bplwt40q....@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) {}
_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to