这样的东西有什么用和解释?:
int capacity;
int** number;
this->number = new int*[this->capacity];
我正在为考试而学习,在考试中,他们提出了使用指针到指针对象并从中创建动态数组的要求。有两个班级;钱包和钱包管理员。在解决方案中,他们在 WalletKeeper 的头文件中执行了此操作:
private:
Wallet** wallets;
int capacity;
int size;
/*other stuff below this*/
在构造函数中:
WalletKeeper::WalletKeeper(int capacity)
{
this->capacity = capacity;
this->size = 0;
this->wallets = new Wallet*[this->capacity];
this->initiate();
}
我了解这样的基本动态数组:
Wallet * wallets = new Wallet[capacity];
这意味着您要创建一个指针,该指针指向创建此钱包数组的内存位置,因此您可以更改这些内存插槽的内容。但是你为什么要创建一个指向指针数组的指针呢?什么用途?
钱包没有自己的数组,否则我会理解它,因为我读了这个:初始化指向多维数组的动态指针的正确方法?
教授们正在休假,直到进一步的麻烦。