It seems pointers and dynamic arrays are giving me a hard time.
Heres part of the assignment. We have to create a class named Student that has three member variables. One of the variables is called classList – "A dynamic array of strings used to store the names of the classes that the student is enrolled in"
My problem is when Im trying to send classList from my input function to my setClassList function. I keep getting the error "subscript requires array or pointer type' and I have no clue what that means. Heres some pieces of my code.
- typedef char* CharPtr;
-
-
class Student
-
-
{
-
public:
-
~Student();
-
void input();
-
void output();
-
void setNumClasses(int);
-
int getNumClasses();
-
void setClassList(char);
-
char getClassList();
-
void setName(char);
-
char getName();
-
void reset();
-
-
-
private:
-
char _name;
-
int _numClasses;
-
char _classList;
-
};
-
void Student::input()
-
{
-
CharPtr classList;
-
classList = new char[];
-
int numberClasses;
-
char name;
-
-
cout<<"Enter students name ";
-
cin>>name;
-
setName(name);
-
-
cout<<"Enter the number of classes student is taking ";
-
cin>>numberClasses;
-
setNumClasses(numberClasses);
-
-
for(int counter = 0; counter < numberClasses; counter++)
-
{
-
cout<<"Enter name of class ";
-
cin>>classList[counter];
-
setClassList(classList[counter]);
-
}
-
-
void Student::setClassList(char classList)
-
{
-
int index = 0;
-
_classList = classList[index];
-
}
Now this isnt all my code, these are just the snipets Im having problems with. Oh and the classList is a char because we havent gone over strings yet.
Thanks.