error: passing as 'this' discards qualifiers
Dec 29, 2010 at 5:38pm UTC
I been having this "error: passing as 'this' discards qualifiers" which i didnt understand it clearly. Any idea where i mistaken? I have surfing the net to look for some clues but unlucky though...Here are some code of mine. I have other classes too...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
class Subject
{
private :
string subCode;
vector<string>facOffer;
set<Student>stuTaken;
public :
Subject();
Subject(string subCode,set<string>facOffer1);
string getSubCode();
void setStuTaken(Student stud);
void dropStuTaken(Student stud);
void print();
};
void Subject::print()
{
cout<<"Subject code :" <<subCode<<endl;
cout<<"Faculty Offer : \n" ;
for (int j=0;j<facOffer.size();j++)
{
cout<<j+1<<" . " <<facOffer[j]<<endl;
}
cout<<endl;
cout<<"Registered student : \n" ;
if (stuTaken.size()==0)
{ cout<<" ---ZERO student registration.---\n" ;}
else
{ for (int j=0;j<stuTaken.size();j++)
{
set<Student>::iterator it=stuTaken.begin();
while (it!=stuTaken.end())
{
cout<<"Student Record no. " <<j+1<<" . \n" ;
it[j].print(); ///////error line
it++;
}
}
}
}
void Subject::dropStuTaken(Student stud)
{
set<Student>::iterator it=stuTaken.begin();
while (it!=stuTaken.end())
{ if (it->getName()==stud.getName()) //////error line
{
stuTaken.erase(it);
cout<<"Deleted" ;
}
it++;
}
}
Thanks in advance.
Last edited on Dec 29, 2010 at 5:40pm UTC
Dec 29, 2010 at 5:40pm UTC
the problem is in class Student, check your const functions
Dec 29, 2010 at 5:42pm UTC
My Student class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class Student
{
private :
string name;
string faculty;
vector<string>subject;
public :
Student();
Student(string name,string faculty);
void registerSubject(set<string>sub);
void print();
string getName();
string getSubject(int i);
void dropStudFromSubject(set<string>sub);
int getSubjectSize();
};
Last edited on Dec 29, 2010 at 5:43pm UTC
Topic archived. No new replies allowed.