What is the use and explanation of something like this?:
int capacity;
int** number;
this->number = new int*[this->capacity];
I'm studying for an exam and in a test exam they put the requirement of using a pointer-to-pointer object and making a dynamic array from it. There are two classes; Wallet & WalletKeeper. In the solutions they did this in the header-file of WalletKeeper:
private:
Wallet** wallets;
int capacity;
int size;
/*other stuff below this*/
And in the constructor:
WalletKeeper::WalletKeeper(int capacity)
{
this->capacity = capacity;
this->size = 0;
this->wallets = new Wallet*[this->capacity];
this->initiate();
}
I understand a basic dynamic array like this:
Wallet * wallets = new Wallet[capacity];
This would mean you make a pointer which points to the place in the memory where this array of Wallets is made, so you can change the content of those memory slots. But why would you ever make a pointer to an array of pointers? What's the use?
Wallet has no array of its own, I would've understood it otherwise because I read this: The correct way to initialize a dynamic pointer to a multidimensional array?
Professors are on vacation until further ado.