C++ 嵌套类模板专门化未正确匹配+;msvc内部错误
这个问题由两部分组成,从(A)到……嗯。。。(C)C++ 嵌套类模板专门化未正确匹配+;msvc内部错误,c++,visual-studio,templates,template-meta-programming,template-specialization,C++,Visual Studio,Templates,Template Meta Programming,Template Specialization,这个问题由两部分组成,从(A)到……嗯。。。(C) 模板结构外部{ /* (A) 如果内部的模板参数相同,请提供匹配项 作为外部。在一般情况下做一些不同的事情(未显示) */ 模板struct Inner1; 模板结构Inner1下面是一种完成案例(B)的方法 templatestruct-Inner; 模板 结构内部{enum{value=a};}; 模板结构外部{ 类型定义内部结果; }; 无效代码(){ 外部::结果::值;//确定, } 唯一的限制是内部不能再位于原始类的私有部分(例
模板结构外部{
/*
(A) 如果内部的模板参数相同,请提供匹配项
作为外部。在一般情况下做一些不同的事情(未显示)
*/
模板struct Inner1;
模板结构Inner1下面是一种完成案例(B)的方法
templatestruct-Inner;
模板
结构内部{enum{value=a};};
模板结构外部{
类型定义内部结果;
};
无效代码(){
外部::结果::值;//确定,
}
唯一的限制是内部不能再位于原始类的私有部分(例如,如果它是外部的一个实现细节,则应具有受限的访问权限)。但要求Inner2的模板类型参数必须仍然能够变化。
template< unsigned a > struct Outer {
/*
(A) Provide a match if the template parameter of Inner is the same
as Outer. Do something different in the general case (not shown)
*/
template< unsigned b > struct Inner1;
template<> struct Inner1<a> { enum { value = a }; };
/*
(B) Same idea as (A), but we want an additional template parameter
*/
template< typename T, unsigned b > struct Inner2;
template< typename T > struct Inner2< T, a > { enum { value = a }; };
typedef Inner1<a> Result1;
typedef Inner2<int, a> Result2;
};
// (C) Alternative way of defining our specializations?
template< unsigned a > template<>
struct Outer<a>::template Inner1<a> {};
template< unsigned a > template< typename T >
struct Outer<a>::template Inner2<T, a> {};
void code() {
Outer<1>::Result1::value; // OK,
Outer<1>::Result2::value; // error C2027: use of undefined type 'Outer<1>::Inner2<int,1>'
}
template< typename T, unsigned b, unsigned a > struct Inner;
template< typename T, unsigned a >
struct Inner< T, a, a > { enum { value = a }; };
template< unsigned a > struct Outer {
typedef Inner<int, a, a> Result;
};
void code() {
Outer<1>::Result::value; // OK,
}