Hi! I'm a little stuck in this project I am trying to program that acts as a class roster. My plan was to create a class with the variables name, numClasses, and classList. Basically I want each student variable to have a dynamic array attached to it. Then I want to be able to create another dynamic array of those student variables to create a class roster that can show every student's classes. I am having trouble with the operators >> and <<. Here is what I have so far, I am omitting my constructors:
the following program uses std::unique_ptr instead of raw C-style pointers which can be unsuitable for your program because the object is acquiring resources but not through the ctor - so even if you provided a dtor with delete[] etc (and also provided the rule of 3/5) there is no guarantee that another object would not be initialized entirely on the stack but it's dtor would then try to call delete[] on a stack allocated variable which is not safe: http://stackoverflow.com/questions/441831/calling-delete-on-variable-allocated-on-the-stack
for (int i = 0; i <= student.numClasses; i++) c-style arrays are null terminated and the last element of the array is reserved for the '\0', so you need to stop the loop at least 1 less than i. so the correct loop would be:
Oh my gosh thank you! You are a gift! So now that I have the basic input and output capabilities, I can create another dynamic array of those student variables, correct? In order to have a fully functioning class roster? Or would I be taking too much away from the freestore with all the dynamic arrays I am creating?
So now that I have the basic input and output capabilities, I can create another dynamic array of those student variables, correct?
one possible dynamic allocation on top of another! in my opinion that'd be too unsafe as far as memory managment is concerned unless you really know what you're doing. instead, i'd strongly suggest using std::vector<student> as the container of choice if your program design is evolving in these directions, something on the lines of: