I want to remove a particular student object for a given roll no. from a students list using erase operation in STL. Following are my class designs. But the compiler shows the following error message at place where I used the erase function.
no instance of overloaded function "std::vector<_Tp, _Alloc>::erase [with _Tp=Student, _Alloc=std::allocator<Student>]" matches the argument list -- argument types are: (Student) -- object type is: std::vector<Student, std::allocator<Student>>
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
class Student
{
int roll;
char *name;
int score;
public:
Student(int r=0)
{
roll=r;
}
void get_data()
{
cout<<"Enter roll : ";
cin>>roll;
cout<<"Enter name : ";
cin>>name;
cout<<"Score : ";
cin>>score;
}
void show_data()
{
cout<<"Roll : "<<roll<<endl;
cout<<"Name : "<<name<<endl;
cout<<"Score : "<<score<<endl;
}
int ret_score()
{
return score;
}
int ret_roll()
{
return roll;
}
};
class Student_array
{
public:
vector <Student> Student_array;
vector <Student>::iterator it;
void add_student()
{
Student s;
s.get_data();
Student_array.push_back(s);
}
void remove_student()
{
int roll;
cout<<"Enter roll no. of the student to be removed : ";
cin>>roll;
for(int i=0;i<Student_array.size();i++)
{
if(roll==Student_array[i].ret_roll())
{
Student_array.erase(Student_array[i]);
break;
}
}
cout<<"Roll no. not found enter a valid roll no.\n";
}
};