Hey all,
I'm pretty new to C++ so forgive how simple this question probably will be.
I'm creating a class which performs operations on instances of another class which it stores in memory. My problem is that I don't know how many instances there will be.
Basically, I have a class called 'employee' which handles the details of each record in my program. I'm creating a class called 'directory' which will support adding/deleting/searching/
sorting the list of employees. As this is for a Uni assignment, I'm not storing this in any form of a datasource, but am just keeping it in memory during runtime.
I was thinking of using some sort of a dynamic pointer array, but I'm not quite sure how to implement this. I know I can create a pointer array using the new keyword and can specify the size of the array during runtime. In this case, how would I resize the array to add a new record or to delete an old one? I've come across the malloc and realloc functions from C, but I want to use C++ only code.
I can create a function the creates a new dynamic array of a size 1 greater that the existing array, copy the contents of the old array, add the new record, and delete the old array, but this seems like a round about way to go about this.
Sorry about the poor explanation, I'm still getting used to the terminology etc.
Regards,
Esulin
Start Free Trial