Thursday 15 May 2014

c++ - How to compare vector? -



c++ - How to compare vector? -

how compare 2 vectors? both cointains integer values:

void interaction(vehicles::position &pos, int number, enviroment object) { (auto = object.x.begin(); i<object.x.end(); i++) (auto j = object.y.begin(); j<object.y.end(); j++) if (pos.x[number] == object.x[i] && pos.y[number] == object.y[j]) cout << "\ninteraction\n"; }

first vector (declared in class):

int remaining_move; struct position{ vector<int> x; vector<int> y; }pos;

second:

struct enviroment { vector<int> x; vector<int> y; string graphic; };

errors:

object.x[i]

this wrong. work if i numeric index, it's not: it's iterator.

instead:

*i

i hence farther suggest calling other i; how it?

also, inner loop status wrong. wrote i, rather j. twice. [edit: , you've fixed in question, reason]

c++ vector

No comments:

Post a Comment