I have a program that creates a struct. It also has a class that creates a pointer to an array of structs that is created.
I'm having trouble accessing the elements of the structs in the array, with the pointer.
Below is a sample of the code.
Struct definition in the header file.
/* Definition of the Course struct*/
typedef struct Course
{
string cID;
int units;
char grade;
};
Actual usage in the source file.
/*declare Course Array*/
Course cArray[MAX];
/*
=======================================================================================================================
Person Constructor
initializes Student ID,
initializes pointer to array of course records,
and sets the current course count to 0.
=======================================================================================================================
*/
Person::Person(int idNum)
{
id = idNum;
Course *aPtr = cArray;
cCount = 0;
}// end Student constructor
/*
=======================================================================================================================
Student function addCourse that adds the courses
updates the course count,
and auto calculates the GPA.
=======================================================================================================================
*/
void Student::addCourse(string cou, int uni, char gra)
{
aPtr[cCount]->cID = cou; // add the course informaion.
aPtr[cCount]->units = uni;
aPtr[cCount]->grade = gra;
}
I was under the impression that i could use the -> operator.
I tried to also acces it like this:
aPtr ->cID = cou;
aPtr ++;
Can anybody give me a hint to what I am doing wrong??