Sim*_*ann 5 c++ template-specialization visual-c++-2012
我有一个模板和一个专门化定义如下:
template<typename T>
struct SomeTemplate final
{
};
template<>
struct SomeTemplate<int> final
{
};
int main()
{
SomeTemplate<int> test; // <-- error
}
Run Code Online (Sandbox Code Playgroud)
使用 Visual C++ 2012 编译出现以下错误:
error C2913: explicit specialization; 'SomeTemplate<T>' is not a specialization of a class template
with
[
T=int
]
Run Code Online (Sandbox Code Playgroud)
当我删除时它编译得很好并且做正确的事情
final符template<>专业化第一种情况对我来说有一定意义,因为它很可能final也限制了模板的专业化(而不仅仅是继承)。第二种情况对我来说有点奇怪,因为我认为这应该是一个语法错误。
这种行为正确吗?