#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class A
{
public :
void getData();
void putData();
bool operator==(const A &) const;
private :
int x;
char name[90];
};
vector< A > v;
void A :: getData()
{
cout << "id = ";
cin >> x;
cout << "\nname = ";
cin >> name;
}
void A :: putData()
{
cout << "size of vector is " << Aref.size() << endl;
cout << x << " : " << name << endl;
}
bool A :: operator==(const A &t) const
{
return ( x == t.x && (strcmp(name, t.name) == 0) );
}
int main()
{
for(int i=0; i < 3; i++)
{
v.push_back(A());
v[i].getData();
v[i].putData();
}
vector< A >::iterator beg = v.begin(), en = v.end();
v.erase( find(beg, en, v[1]) );
//Deletes the second object, but I want to search the whole object
//array by its attribute such as name or x(employee number) and then
//delete the object, if match found
cin.ignore(numeric_limits< streamsize >::max(), '\n');
cin.get();
return 0;
}
I want to search the array of objects in terms of the objects attributes (such as x, name)
when I find the particular value for any object(such as x or name) i delete that object
if possible how do I use remove, find_if or functors?