samedi 18 avril 2015

Why this C++ program failed in compilation?

I was reading this. I tested this program on code blocks 13.12 IDE which supports C++11 but it is getting failed in compilation & compiler shows multiple errors. Look the program. It works fine on online compiler see this



// bad_array_new_length example
#include <iostream> // std::cout
#include <exception> // std::exception
#include <new> // std::bad_array_new_length

int main() {
try {
int* p = new int[-1];
} catch (std::bad_array_new_length& e) {
std::cerr << "bad_array_new_length caught: " << e.what() << '\n';
} catch (std::exception& e) { // older compilers may throw other exceptions:
std::cerr << "some other standard exception caught: " << e.what() << '\n';
}
}


Compiler errors:


7 12 [Error] expected type-specifier


7 37 [Error] expected unqualified-id before '&' token


7 37 [Error] expected ')' before '&' token


7 37 [Error] expected '{' before '&' token


7 39 [Error] 'e' was not declared in this scope


7 40 [Error] expected ';' before ')' token


9 5 [Error] expected primary-expression before 'catch'


9 5 [Error] expected ';' before 'catch'


What is going wrong here? Is it compiler bug or C++11 isn't fully supported in code blocks 13.12 IDE?


Please help me.


Aucun commentaire:

Enregistrer un commentaire