捕获异常
double divideNumber(double num1,double num2){ if (num2==0) { throw exception(); } return num1/num2; }
try{ cout << divideNumber(1,3) << endl; cout << divideNumber(1,0) << endl; }catch(const exception& exp) { cout << "An exception was caught !" << endl; }
函数多参数返回(不通过返回参数)
void addNum(int& a) { a++; }
时间: 2024-10-14 07:59:50