I've got two vector objects called A and B. The MyType class does not have a field ID and I want to get the MyType* which are in A but not in B.
Since I do not have an ID need to compare based on the string field.
My object's class looks like this
class Object
{
public:
Object();
string Name;
bool Mode;
string something;
Int range;
}
vector<Object*> a; //asssume filled with objects
vector<Object*> b; //asssume filled with objects
vector<Object*> ret;
Now I want to get diff of (a,b)
- all the members that are in a and not b.
How to proceed on this. I tries using strcmp()
to do the comparison but it is not working.
This seems like a perfect job for
set_difference
( http://www.cplusplus.com/reference/algorithm/set_difference/ ).Provide a comparator for your objects, sort the two vectors (using that comparator), and then use
set_difference
(using that same comparator) to get the objects that are in the first, but not the second.