GCC Error: Explicit Specialization in Non-Namespace Scope
Question:
Why does the following code fail to compile in GCC when explicitly specializing a member function template within a class?
template<typename T> struct Widget { template<typename U> void foo(U) { } template<> void foo(int*) { } };
Answer:
According to the C standard ([temp.expl.spec], paragraph 2), explicit specializations may be declared in any scope in which the corresponding primary template may be defined. Therefore, the code should compile in GCC as well.
GCC Bug and Reporting:
This failure to compile in GCC is likely a bug. To report it, follow these steps:
Standard Reference:
The C standard section [temp.expl.spec] paragraph 2 states:
An explicit specialization may be declared in any scope in which the corresponding primary template may be defined.
The above is the detailed content of Why Does GCC Fail to Compile Explicit Specializations of Member Function Templates Within a Class?. For more information, please follow other related articles on the PHP Chinese website!