【发布时间】:2015-04-10 11:34:10
【问题描述】:
我想编写一个包装函数,我可以将一些类对象的构造函数初始化参数传递给它。然后这个包装器将使用这个列表并在定义该类的新对象时传递给构造函数。不确定为此目的使用什么 STL 或任何其他数据类型。基本上在下面的代码中应该为 argument_list 使用什么数据类型。有什么图书馆可以提供帮助?
一些透视代码
class abc{
int a_;
char b_;
public:
abc(int a, char b)
:a_(a), b_(b)
{
}
}
// Wrapper
template <typename T>
void create_object_wrapper(argument_list list) // assuming argument_list can
//hold the parameters as
//intended
{
abc v1(list); //The use case I want
}
int main()
{
create_object_wrapper(1,'a'); // initialize object with (1, 'a')
return 0;
}
提前致谢。
【问题讨论】:
-
您可能想了解template parameter packs,
标签: c++ templates boost constructor stl