Consider following class :
class Subject
{
private:
char* name; // I must use char pointers, it's for school.
int grade;
public:
Subject() {
name = NULL;
grade = 0;
}
Subject(char *n, int g) {
name = new char[strlen(n)];
strcpy(name,n);
grade = g;
}
~Subject() {
delete name;
}
void operator=(const Subject &obj) {
strcpy(name, obj.name);
grade = obj.grade;
}
}
So it is pretty simple data structure with its special functions. I'm new to overload operators so it is probably not correctly implemented. Now, what I try to do is make a simple array of those objects. Consider my main function :
Subject *collection = new Subject[3];
char tmp[100];
int grade;
for(int i = 0 ; i < 3; i ++){
cin >> tmp;
cin >> grade;
collection[i] = new Subject(tmp,grade);
}
This returns error saying no match for operator= in ..etc. So I get that they don't know what to do when they see '=', so I need to define it. How do I do it. Again, point is to make simple list of Subject objects.(I can't use vector, it is for school)