C++ variadic constructor - pass to parent constructor

十年热恋 提交于 2019-12-07 08:44:01

问题


I have th following code:

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, ????)
    {}
};

How can I do that?

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!

Thanks


回答1:


You cannot forward on to an ellipsis. The second constructor will have to take a va_list, I think it is.

This would be possible with C++0x's base constructor forwarding, or variadic templates.



来源:https://stackoverflow.com/questions/6179812/c-variadic-constructor-pass-to-parent-constructor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!