相关疑难解决方法(0)

如何在可变参数模板中包含多个参数包?

函数one()接受一个参数包.函数二()接受两个.每个包都被约束为包裹在类型AB中.为什么不可能实例化两个()

template <typename T>
struct A {};

template <typename T>
struct B {};

template <typename... Ts>
void one(A<Ts> ...as) {
}

template <typename... Ts, typename... Us>
void two(A<Ts> ...as, B<Us> ...bs) {
}

int main() {
  auto a = A<int>();
  auto b = B<int>();

  // Just fine
  one();
  one(a);
  one(a, a);

  // All errors    
  two();
  two(a);
  two(a, b);
}
Run Code Online (Sandbox Code Playgroud)

试过gcc和clang.

sam@wish:~/x/cpp$ gcc -std=c++0x variadic_templates.cpp 
variadic_templates.cpp: In function ‘int main()’:
variadic_templates.cpp:23:7: …
Run Code Online (Sandbox Code Playgroud)

c++ variadic-templates c++11

49
推荐指数
4
解决办法
2万
查看次数

标签 统计

c++ ×1

c++11 ×1

variadic-templates ×1