【发布时间】:2018-10-04 05:07:11
【问题描述】:
当我尝试在 Visual C++ (2015) 中运行此代码时
template<int V>
struct outer
{
template<int U, bool>
struct inner;
};
template<int V>
template<bool B>
struct outer<V>::inner<V, B> { enum { value = 0 }; };
int main()
{
return outer<1>::inner<1, false>::value;
}
我得到了错误
Temp.cpp(13): error C2027: use of undefined type 'outer<1>::inner<1,false>'
Temp.cpp(13): note: see declaration of 'outer<1>::inner<1,false>'
Temp.cpp(13): error C2065: 'value': undeclared identifier
但是,it compiles and runs fine on GCC 和 Clang。
三个问题:
如果部分特化不是部分特化,它在做什么?
为什么会发生这种情况?是 bug 还是这段代码真的有问题?
是否有一种解决方法可以让您在内部模板类中仍然使用内部模板类,或者是将模板参数移到外部的唯一解决方案?
【问题讨论】:
-
升级到 VS 2017?它在那里编译而没有抱怨。
-
@1201ProgramAlarm:Ack,所以这是一个错误?不幸的是,升级说起来容易做起来难......
-
无法用 VS2017 重现。
标签: c++ templates visual-c++ inner-classes partial-specialization