Руководство по стандартной библиотеке шаблонов STL

       

Compile this code without defining


#include <stl.h>

// Compile this code without defining the symbol OS_USE_EXCEPTIONS.

int main () { vector<int> v; v.pop_back (); // Generates an empty object error. return 0; }



#include <stl.h>

// Compile this code with the symbol OS_USE_EXCEPTIONS defined.

int main () { vector<int> v; try { v.pop_back (); // Generates an exception. } catch (const char* str) { cout << "Caught exception " << str << endl; } return 0; }



#include <stl.h>

// Compile this code without defining OS_USE_EXCEPTIONS.

void my_handler (int code_, const char* str_) { cout << "Caught " << str_ << " [code " << code_ << "]" << endl; }

int main () { os_handler_function_t old_h = os_set_error_handler (my_handler); vector<int> v; v.pop_back (); // Generates an empty object error. cout << "returned from pop_back()" << endl; os_set_error_handler (old_h); v.pop_back (); // Generates an empty object error. cout << "successful termination" << endl; return 0; }


Содержание раздела