Construction a vector from the concatenation of 2 vectors

后端 未结 6 432
梦谈多话
梦谈多话 2021-01-12 22:45

Is there a way to construct a vector as the concatenation of 2 vectors (Other than creating a helper function?)

For example:



        
6条回答
  •  执笔经年
    2021-01-12 23:26

    class Vector : public vector
    {
    public:
        Vector operator+(const Vector& vec);
    };
    
    Vector Vector::operator+(const Vector& vec)
    {
        for (int i = 0; i < vec.size(); i++)
        {
            this->push_back(vec[i]);
        }
    
        return *this;
    }
    

提交回复
热议问题