vector<int> printMatrix(vector<vector<int> > matrix) {
if (matrix.empty()) {
return vector<int>();
}
this->matrix = std::move(matrix);
int startRow = 0, lastRow = this->matrix.size() - 1;
int startCol = 0, lastCol = this->matrix[0].size() - 1;
while (startRow <= lastRow && startCol <= lastCol) {
printCircle(startCol, lastCol, startRow, lastRow);
++startCol, --lastCol, ++startRow, --lastRow;
}
}
它工作正常,而变量 startRow 小于 lastRow 。然而,一般来说,当 startRow 大于 lastRow 时,应该退出 while 循环但引发 Exception: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) 代替。如图所示,我对引发异常感到困惑。