我在C ++中创建了以下2D数组:
template <typename T> class Array2D {
private:
T **items;
int m,n;
public:
Array2D(int m, int n, T initValue = 0) {
this->m = m;
this->n = n;
this->items = new T*[m];
for (int i = 0; i < m; i++) {
this->items[i] = new T[n];
memset(this->items[i], initValue, sizeof(T) * n);
}
}
...
}
我想要做的是删除给定索引处的行/列。
对于行,我正在考虑用下面的行交换感兴趣的行,直到我到达最后一行,然后删除最后一行:
while (removeIndex < m - 1) {
swap(removeIndex, removeIndex + 1);
removeIndex++;
}
delete [] items[m];
m--;
但我怎样才能删除该列?