Sunday, 15 September 2013

c++ - Using the same object to compare each others vectors -



c++ - Using the same object to compare each others vectors -

suppose create constructor set::set(vector<int> &v) takes vector , saves it. , have union method takes argument of type set , compare vector contents of originalset initialized constructor in beginning.

how go doing this operator? know how union function works, don't understand how attain vector argument of union method.

class set { public: set(vector<int> &); void setter(vector<int> &); set union(set); private: vector<int> originalset; }; set set::union(set s) { } set::set(vector<int> &v) { setter(v); } void set::setter(vector <int> &v) { originalset = v; }

in function:

set set::union(const set& s) // take const& { originalset; // set owned "this" object s.originalset; // set owned set passed in // 1 [wrong] implementation might combine them set full(originalset); full.originalset.insert(full.originalset.back(), s.originalset.begin(), s.originalset.end()); homecoming full; }

that not right implementation of union obviously, should show tools need write correctly.

c++ oop vector this

No comments:

Post a Comment