22
此代碼有效;在C++中拋出異常異常
int at(int index) {
if(index < 1 || index >= size)
throw 0;
return x[index];
}
但這並不
int at(int index) {
if(index < 1 || index >= size)
throw std::out_of_range;
return x[index];
}
我得到的錯誤 「之前預計主要表達 ';'」。現在...我很驚訝,因爲我知道的std :: out_of_range存在,我有
#include <stdexcept>
這兩個函數有什麼區別? – kennytm 2010-04-25 19:58:51
oops,複製粘貼錯誤,現在沒關係。 – Suugaku 2010-04-25 20:00:22
爲什麼是0越界? – 2010-04-25 22:23:28