Pointers Question

When you use a new pointer to create a new array to create a bigger array for more space, whats the best way to code it?

And when you delete it, you first need to make sure whatever is in the newly created array is pointed at by your first pointer, right? I'm just having some runtime errors with these pointers and the whole copy method and such.
Best way is to use std::vector.

What to you mean by first pointer? When you delete the array the pointer has to point to the first element in the array.
What I'm saying is in my class, I have a data member that is a pointer. Then I use my constructor to create an initial array set to NULL. Then I get an object to put in my array. Put the first object in the array. Then after that, every other object will cause the array to need to be bigger. Thats where the second pointer comes in. In my copy method, what I'd do is create a new pointer and use that pointer to create a new array, big enough to fit my new object(s) into it. That's where I'm confused. The whole, make sure the old pointer points to the new array and delete the old array. I always end up getting my statements mixed up and deleting the array I want or making the new array equal to the old array and I defeat the whole purpose of creating the new array.
Topic archived. No new replies allowed.