如何在 C++ 中捕获错误的数组引用?为什么以下代码不起作用:
#include <exception>
int * problemNum = new int;
int (* p [100])() = {problem1, problem2, problem3};
...
try {
cout << (*p[*problemNum-1])();
}
catch (exception){
cout << "No such problem";
}
我的编译器说:Euler.exe 中 0xcccccccc 处的未处理异常:0xC0000005:访问冲突。当我通过输入0
*problemNum 来启动错误引用时。