Array of Pointers to Objects

Can someone explain this (and maybe show me a simple example):

I am supposed to code a class (Doc) that uses pointers to point to objects of a sub-class (Str), meaning one Doc holds multiple Str objects, via an array of pointers. These pointers are created by tens (10s), meaning that first 10 pointers are created, then when all of them are assigned to their Str, 10 more are created, and when they are used 10 more are created and so on...

How is this done without causing a crash? Say 10 pointers are created, and they take a block of memory. Lets just say that the computer then puts something else right after that block of memory, and then more pointers are supposed to be created, pointing to after that second block, but in respect to the first one.
So:

POINTERS 1 THEN SOMETHING ELSE POINTERS 2
__________ ___________________ __________

Pointers 2 is a block of memory to which the second part of the array of pointers points to. I hope you understand what I am asking.

Anyway, this is the theory, I would like to know this just for extra understanding. Also, can someone show me a simple example of how this is done?
Thanks




Last edited on
closed account (D80DSL3A)
The problem you see is real. The usual method is to allocate a new array of 20 Str pointers, copy the values from the old array to the new array then release the memory for the old array.
Topic archived. No new replies allowed.