#include <iostream>
    #include <vector>
    #include <algorithm>

    using namespace std;

    class A
    {
          public :
          void getData(vector< A > &);
          void putData(vector< A > &);
      
          private :
                  int x;
                  char name[90];
    };
    vector< A > v;

    void A :: getData(vector< A > &Aref)
    {
         cout << "id = ";
         cin >> x;
         cout << "\nname = ";
         cin >> name;
 
    }

    void A :: putData(vector< A > &Aref)
    {
         cout << "size of vector is " << Aref.size()  << endl;
         for(int i=0; i < Aref.size(); i++)
         cout << Aref[i].x << " : " << Aref[i].name << endl;
         
         cin.ignore(numeric_limits< streamsize >::max(), '\n'); 
         cin.get();
    }
     

    int main()
    {
        for(int i=0; i < 3; i++)
        {
        v.push_back(A());
        v[0].getData(v);
        v[0].putData(v);
        }
        vector< A >::iterator beg = v.begin(), en = v.end();
        //v.erase( find(beg, en, v[1]) ); -->DOESN'T WORK
        return 0;   
    }

I have used this
v.erase( find(beg, en, v[1]) ); (Line 48)
to search and delete an object from the array
vector< A > v; (A is the name of class)

Does find accepts the object as its 3rd if not what ways can a follow to delete an object.In fact I want to search the particular attribute(such as id, name) value from the array of objects and then delete that object.

please advice?

Did you find any error?

Did you find any error?

well a new tab opened when i compiled it.( stl_algo.h opened) and

got many lines of error i don't understand

C:\Dev-Cpp\include\c++\3.4.2\bits\stl_algo.h In function `_RandomAccessIterator std::find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<A*, std::vector<A, std::allocator<A> > >, _Tp = A]':

314 C:\Dev-Cpp\include\c++\3.4.2\bits\stl_algo.h instantiated from `_InputIterator std::find(_InputIterator, _InputIterator, const _Tp&) [with _InputIterator = __gnu_cxx::__normal_iterator<A*, std::vector<A, std::allocator<A> > >, _Tp = A]'


and many more lines, I dont get it
compiler (DevC++ version 4.9.9.0)

If you look at this page http://www.cplusplus.com/reference/algorithm/find/ you'll see that find() requires the == operator to be defined on your class, and it's not.

Something like this probably:

bool A :: operator ==(const A &t) const
{
	return ((x == t.x) && (strcmp(name, t.name) == 0));
}

On a side note, why did you define putData() as a member-function of A even though it doesn't do anything with the A it's called from?

And why does getData() take an argument which it doesn't use?

If you look at this page http://www.cplusplus.com/reference/algorithm/find/ you'll see that find() requires the == operator to be defined on your class, and it's not.

Something like this probably:

bool A :: operator ==(const A &t) const
{
	return ((x == t.x) && (strcmp(name, t.name) == 0));
}

On a side note, why did you define putData() as a member-function of A even though it doesn't do anything with the A it's called from?

And why does getData() take an argument which it doesn't use?

Thanks, I got this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.