【发布时间】:2016-07-06 02:58:53
【问题描述】:
以下源代码来自: Understanding partial specialization of inherited nested class templates
#include <type_traits>
struct Base
{
template<class U, class _ = void> struct Inner: std::true_type {};
template<class _> struct Inner<char, _>: std::false_type {};
};
struct Derived : Base
{
};
template<class _> struct Derived::Inner<int, _>: std::false_type {};
我有一个关于专门继承类的问题,所以我搜索了一下,找到了上面的问题。上述问题中的源代码在 gcc/clang 中编译时没有任何问题,但 msvc 拒绝编译它,发出 C2427(请参阅https://msdn.microsoft.com/en-us/library/10het5hx.aspx)。
我认为上面的情况(特化非模板类的嵌套模板类)与https://msdn.microsoft.com/en-us/library/10het5hx.aspx中描述的情况(定义模板类的嵌套非模板类)有很大不同。
msvc 与 gcc/clang 哪一个是错误的?还是只是标准不清楚来指定这种行为?
我希望 msvc 是错的...
【问题讨论】:
标签: c++ inheritance language-lawyer inner-classes template-specialization