Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用获取模板参数的类型_C++_Templates_Template Templates - Fatal编程技术网

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
?你的编译器是什么?