Inserting a variadic argument list into a vector?

后端 未结 6 1055
别那么骄傲
别那么骄傲 2020-12-09 02:44

Forgive me if this has been answered already, as I couldn\'t find it...

Basically I have an object that needs to take a variadic argument list in it\'s constructor

6条回答
  •  醉梦人生
    2020-12-09 03:28

    class Blob
     {
        std::vector _v;
     public:
    
        template
        Blob(Args&&... args)
        : _v(std::forward(args)...)
        {  }
    
    };
    
    int main(void)
    {
        const char * shapes[3] = { "Circle", "Triangle", "Square" };
    
        Blob b1(5, "C++ Truths"); 
        Blob b2(shapes, shapes+3);
    }
    

    Example from C++11 Truths looks simple enough...;) Not a complete solution but might give you some ideas.

提交回复
热议问题