基本 (Student) クラスの配列を動的に割り当て、派生 (Math) クラスへのポインターを各配列スロットに割り当てようとしています。基本クラスへの単一のポインターを作成し、それを派生クラスに割り当てることで機能させることができますが、動的に割り当てられた基本クラスの配列へのポインターに割り当てようとすると失敗します。以下に使用しているコードの断片を投稿しました。基本的に私の質問は、動的に割り当てられたものが機能しないのはなぜですか?
Student* studentList = new Student[numStudents];
Math* temp = new Math(name, l, c, q, t1, t2, f);
studentList[0] = temp;
/*Fragment Above Gives Error:
main.cpp: In function âint main()â:
main.cpp:55: error: no match for âoperator=â in â* studentList = tempâ
grades.h:13: note: candidates are: Student& Student::operator=(const Student&)*/
Student * testptr;
Math * temp = new Math(name, l, c, q, t1, t2, f);
testptr = temp
//Works