c++ - 可变嵌套模板类型作为参数

标签 c++ c++11 parameters variadic-templates

<分区>

我想要一个可变参数模板类的模板类型的函数参数。下面的代码如何才能合式?

template <typename T>
struct Foo {
  typedef T Base;
};

template <typename... Targs>
struct Bar {
  void get(Targs::Base... args) {} /// Type of the typedef Base of Foo!
};

int main() {
  Bar<Foo<int>, Foo<double>> bar;

  int i = 0;
  double j = 0.0;
  bar.get(i, j);
}

使用 GCC 4.9 C++11 或 5.3。

最佳答案

简单。看我的 typename

template <typename... Targs>
struct Bar {
  void get(typename Targs::Base... args) {} /// Type of the typedef Base of Foo!
};

关于c++ - 可变嵌套模板类型作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35927968/

相关文章:

c++ - 用户定义类型的非类型模板参数

javascript - 我可以使用函数作为参数吗?

c++ - VS2013中继承构造函数

c++ - 从 Derived<X> 到 Base<X> 的 reinterpret_cast 安全吗?

c++ - vector push_back a moved local var in c++11 测试和混淆

sql - 如何在动态SQL查询中设置表名?

Symfony2停止Composer将parameters.yml.dist安装到parameters.yml中

c++ - 将 std::string 拆分为 vector<string> 的正确方法

c++ - Qt图形绘制

c++ - 为什么右值引用与移动语义相关?