CJCoding With Joseph
15free / daySign inCreate account

Safe List Access

Create a class SafeList that wraps a vector<int> and prevents out-of-bounds access.

Requirements:
1. Constructor SafeList(): already provided
2. void add(int value): adds value to the internal vector
3. int get(int index) const: if index is out of bounds, throw a std::out_of_range with the message "Index out of bounds". Otherwise return the element at that index.

Do NOT write a main function.

Expected Output:

10

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
ClassesExceptions
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.