I have a base class called Student and three derived classes of MathStudent, EnglishStudent, and HistoryStudent. I am making a new class called StudentList which is supposed to make a dynamic array of pointers to Student such as
Student** List = new Student*[CurrentSize];
the whole point of the code is to read a text file containing students information and to order them into the list and then access the list to then print out the students information and/or export it into a new file. The problem I am having is with the following block of code:
CurrentSize += numStudents;
for(int i = 0; i < CurrentSize; i++)
{
File.getline(LastName, 20, ',');
File.getline(FirstName, 20);
File.getline(Subject, 8, ' ');
if(Subject == "Math")
{
File>>q1>>q2>>q3>>q4>>q5>>test1>>test2>>final;
MathStudent M(LastName, FirstName, Subject, q1, q2, q3, q4, q5$
Mptr = &M;
List[j] = Mptr;
}
else if(Subject == "English")
{
File>>attendance>>project>>midterm>>final;
EnglishStudent E(LastName, FirstName, Subject, attendance, pro$
List[j] = &E;
}
else if(Subject == "History")
{
File>>paper>>midterm>>final;
HistoryStudent H(LastName, FirstName, Subject, paper, midterm,$
List[j] = &H;
}
j++;
}
Having attempted to debug the code on GDB i found that the segmentation fault is occuring whenever I attempt to pass something into List such as when I say
List[j] = Mptr;
or
List[j] = &M;
But I dont understand why or how this results in a segmentation fault. Please any help is very much appreciated.