Adding elements to a pointer array

I'm trying to add elements onto an 'array', without using vectors. And I was wondering if this sort of thing is possible:

1
2
3
4
5
6
7

void data::add(int newNum) {
	array_length++;
	integer_array = new int[array_length];
	integer_array[array_length]=newNum;
}


It compiles, but I get a long error when I run it:


main: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) 
&((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) 
&& old_size == 0) || ((unsigned long) (old_size) >= (unsigned 
long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * 
(sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 
0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
Aborted



Thanks for any insight you can give me!
elements are numbered form 0 to array_length-1.
you also have to copy the old array.
hamsterman, do I need to delete the original array?

I'm thinking that I do because I want to just point the old array to the new one.
Nevermind, I got it!

Thanks!
Topic archived. No new replies allowed.