[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: error: enclosing class templates are not explicitly specialized
From: |
Thomas Maeder |
Subject: |
Re: error: enclosing class templates are not explicitly specialized |
Date: |
Wed, 09 Sep 2009 09:34:50 +0200 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) |
piotr5@unet.univie.ac.at (Piotr Sawuk) writes:
> In article <87bplwt40q.fsf@madbox3.site>,
> Thomas Maeder <maeder@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) {}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: error: enclosing class templates are not explicitly specialized,
Thomas Maeder <=