我试图将可变参数模板参数存储在一个模板类中,然后在另一个模板类中使用它们。像这样的东西:
template<typename... Args>
struct A{
typedef Args... type; // heh
};
template<typename A_T>
struct B{
void foo(A_T::type... args){}
};
B<A<int,int> > b;
b.foo(2,3);
感谢所有帮助!
最佳答案
您不能定义多种类型!正如所有评论中所建议的那样,std::tuple
是拥有产品类型的正确方法。
typedef std::tuple<Args...> type; // instead of typedef Args... type;
实现调用
B<A<int,int> > b;
b.foo(2,3);
你可以稍微修改你的代码
template<typename... Args>
struct A{
};
template<typename A_T>
struct B{
};
template<template<typename...> class A_T, typename... Args>
struct B<A_T<Args...>>{
void foo(Args... args){
}
};
关于c++ - 存储可变模板参数并在另一个类中使用它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21194533/