C++ 在另一个模板类型内使用模板类型的参数化子类型
是否有可能实现以下行为C++ 在另一个模板类型内使用模板类型的参数化子类型,c++,templates,C++,Templates,是否有可能实现以下行为 template<typename T> struct X { template<const bool Condition> struct Y; template<> struct Y<true> { typedef T Z; }; }; template<typename T> struct A { typedef typename T::Y
template<typename T>
struct X {
template<const bool Condition>
struct Y;
template<>
struct Y<true> {
typedef T Z;
};
};
template<typename T>
struct A {
typedef typename T::Y<true>::Z B; // Error
};
int main() {
X<float>::Y<true>::Z value = 5.0f; // OK
A<X<float>>::B value2 = 5.0f; // Desired behaviour
return 0;
}
模板
结构X{
模板
结构;
模板
结构{
类型定义T Z;
};
};
模板
结构A{
typedef typename T::Y::Z B;//错误
};
int main(){
X::Y::Z值=5.0f;//确定
A::B value2=5.0f;//所需的行为
返回0;
}
试试看
typedef typename T::template Y::Z B;
它在gcc 4.7.2中起作用
尽管gcc抱怨结构内部的完全专门化,所以我不得不添加一个伪参数。很有趣。使用MSVC 2012(平台工具集120)
typedef typename T::template Y<true>::Z B;