C++ 使用获取模板参数的类型
我有下面一段代码没有编译-> 问题是我想从类型中获取模板参数。我所拥有的是C++ 使用获取模板参数的类型,c++,templates,template-templates,C++,Templates,Template Templates,我有下面一段代码没有编译-> 问题是我想从类型中获取模板参数。我所拥有的是使用S=A,我想回到我在制作S时使用的std::vector,并在其他地方使用它 #include <iostream> #include <vector> template <typename T, template<class...> class Container> struct A { using Ttype = T; using ContainerType
使用S=A
,我想回到我在制作S时使用的std::vector
,并在其他地方使用它
#include <iostream>
#include <vector>
template <typename T, template<class...> class Container>
struct A
{
using Ttype = T;
using ContainerType = Container;
Container<T> s;
};
int main()
{
using S = A<int, std::vector>;
S::ContainerType<double> y;
y.push_back(2);
return 0;
}
#包括
#包括
模板
结构A
{
使用Ttype=T;
使用ContainerType=Container;
集装箱;
};
int main()
{
使用S=A;
S::容器类型y;
y、 推回(2);
返回0;
}
我不知道是否有一种方法可以做我想做的事。如果没有添加模板参数,
std::vector
不是一种类型 您可以将ContainerType
声明为,因为Container
本身就是一个模板
template<typename... X>
using ContainerType = Container<X...>;
模板
使用ContainerType=Container;
实际例子中,对于我的实际问题,我需要在中间使用<代码>模板<代码>。因此,类似于
S::template container类型y代码>我不知道为什么。@Mochan在你真正的代码中什么是S
?你的编译器是什么?