Advertisement

07.12.2005 at 11:09AM PDT, ID: 21488856
[x]
Attachment Details

C++ Basics: Dynamic arrays

Asked by Esulin in C++ Builder

Tags: ,

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,
EsulinStart Free Trial
 
Keywords: C++ Basics: Dynamic arrays
 
Loading Advertisement...
 
[+][-]07.12.2005 at 11:13AM PDT, ID: 14424118

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C++ Builder
Tags: array, dynamic
Sign Up Now!
Solution Provided By: Axter
Participating Experts: 3
Solution Grade: A
 
 
[+][-]07.12.2005 at 11:14AM PDT, ID: 14424132

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.12.2005 at 11:17AM PDT, ID: 14424156

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.12.2005 at 12:02PM PDT, ID: 14424570

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.12.2005 at 07:46PM PDT, ID: 14427831

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.13.2005 at 03:17AM PDT, ID: 14429493

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.13.2005 at 08:18AM PDT, ID: 14432001

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32