I have a class vector that I will like to loop through to remove duplicates of a certain variable that belongs to the class.
#include <vector>
#include <iostream>
#include <functional>
#include <thread>
#include <string>
using namespace std;
struct Class {
int x;
string y;
};
void someFunction(vector<Class *> &arr){
arr.push_back(new Class); // y = a
arr.push_back(new Class); // y = b
arr.push_back(new Class); // y = a
arr.push_back(new Class); // y = c
cout << "size of vector is " << arr.size()<<endl;
}
void loopDelete(vector<Class *> &arr){
// how do i delete duplicates of arr.y in this function??
}
int main(){
vector<Class *> foo;
auto t1 = thread(someFunction, ref(foo));
t1.join();
foo.push_back(0);
auto t2 = thread(loopDelete, ref(foo));
t2.join();
cout << "size of vector at end of main is " << foo.size()<<endl;
return 0;
}
Any help or suggestion is greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire