1

I want to push two vectors of integers (id1.a, and id2.a) into vector of integer newId but I got error C2440: 'initializing'

 cannot convert from 'std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>' to 'int'

This my code:

struct Ss {
    std::vector<int> a;
    double b;
    double c;
};

// function
Ss getNewId(Ss id1, Ss id2) {
    Ss newSs = Ss();
    std::vector<int> newId = vector<int>();

    //newId.push_back(id1.a);
    //newId.insert(id1.a.begin(), id1.a.end());
    newId.emplace_back(id1.a.begin(), id1.a.end());
    newId.emplace_back(id2.a.begin(), id2.a.end());

    newSs.a = newId ;

    // some code...//

    return newSs;

Now, I did fix the error using:

std::copy(id1.a.begin(), id1.a.end(), std::inserter(newId, newId.end()));
std::copy(id2.a.begin(), id2.a.end(), std::inserter(newId, newId.end()));

but I really don't know why I can't push a vector inside vector using (insert, or push_back, etc), and I want to learn. Thanks for any help.

David G
  • 94,763
  • 41
  • 167
  • 253
user3823821
  • 91
  • 1
  • 7

0 Answers0