Aish, then you're in for some "fun".
Basically, the way one deals with dynamic arrays is that one maintains a pointer to memory that the program has allocated on the heap.
Let's consider the basics:
int* ptr = new int;
What this code does is dynamically allocate an integer, and store a pointer to it in ptr. You can now access that integer whenever you'd like just by dereferencing the pointer.
1 2
|
*ptr = 3;
std::cout << *ptr;
|
3 |
However, you always need to remember to maintain a pointer to that memory. Otherwise, it's a memory leak: memory is being allocated but never freed, which freeing memory manually is something also need to do. Just as you got that memory from the system, you also need to return it to the system when you're done.
delete ptr;
Now, if you want to make an array, the syntax is a bit different...
1 2 3
|
bool* hassyrup = new bool[3];
//Do stuff.
delete [] bool;
|
If you're creating an array of objects, then bear in mind that the previous two syntaxes will call the default constructor. If you want to call a non-default constructor (this only works intuitively for non-array allocations), you'll need the following syntax:
AClass* classi = new AClass(7, "duck", "goose");
Resizing is where it starts getting painful. When you want to "resize" a dynamic array, what you have to do is actually this:
1. Allocate another array and maintain a temporary pointer to it.
2. Copy over the contents of the first array to the second.
3. Delete the first array.
4. Set your non-temporary pointer to the temporary pointer's value.
Good luck.
-Albatross