How do I catch wrong array reference in C++? Why doesn't the following code work:
#include <exception>
int * problemNum = new int;
int (* p [100])() = {problem1, problem2, problem3};
...
try {
cout << (*p[*problemNum-1])();
}
catch (exception){
cout << "No such problem";
}
My compiler says: Unhandled exception at 0xcccccccc in Euler.exe: 0xC0000005: Access violation. when I initiate bad reference by inputting 0
as *problemNum.