C ++可变参数构造函数 - 传递给父构造函数 [英] C++ variadic constructor - pass to parent constructor
本文介绍了C ++可变参数构造函数 - 传递给父构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
class A{
//Constructor
public: A(int count,...){
va_list vl;
va_start(vl,count);
for(int i=0;i<count;i++)
/*Do Something ... */
va_end(vl);
}
};
class B : public A{
//Constructor should pass on args to parent
public: B(int count,...) : A(int count, ????)
{}
};
我如何做?
注意:我更喜欢在初始化列表中调用构造函数,而不是在构造函数体中。
Note: I would prefer to have call the constructor in the initialization list and not in the constructor body. But if this is the only way, I am also interested to hear how this works!
感谢
推荐答案
你不能转发省略号。第二个构造函数将需要一个 va_list
,我想是。
You cannot forward on to an ellipsis. The second constructor will have to take a va_list
, I think it is.
可以使用C ++ 0x的基本构造函数转换,或可变参数模板。
This would be possible with C++0x's base constructor forwarding, or variadic templates.
这篇关于C ++可变参数构造函数 - 传递给父构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文