Skip to main content
100%

Gist 10288187

✓ Published0🌍 Public
FFranklin Chen
Last edited Apr 9, 2014
Created on Apr 9, 2014

This example demonstrates the importance of bounds checking in C++ vector access. It uses the `std::vector` class and its `.at()` method, which throws an exception when the given index is out of range, in contrast to the unchecked `[]` operator. A loop iterates from zero to four over a vector containing three integers, triggering an out-of-range error that is caught by an `exception` handler. The code also shows a custom destructor message when a `Foo` object, managed via `make_shared`, is cleaned up.

AI-generated description

Similar vizzes