What i want to do is to match allow user to enter for example ID and match that ID with some vector and print it. Here is how my class looks like. (I am trying to do an inventory program).
class Item{
private:
string month;
string name;
int ID;
int actual_qunatity;
public:
void print()const;
void report();
void getdata();
void setname (string itemname){name=itemname;}
void setID(int setID){ID=setID;}
};
class Inventory{
public:
void print2()const;
void report();
void getdata();
void sale();
private:
vector<Item>items;
};
after adding elements to the vector i want to find some element in the vector and print it. here is
void Inventory::sale(){
int ID;
cout<<"Enter ID ";
cin>>ID;
vector<Item>::const_iterator it;
it=find(items.begin(), items.end(), ID);
++it;
}
but i get an error: no matching function for call to ‘find(std::vector::iterator, std::vector::iterator, int&)’
Yes, this is because you have a vector of
Itemobjects and you are telling it to look for an integer. You need to either change your design or simply use a for loop and manually do the check on each object somewhat like this: