Question 9
Back to Exercise
Which member function breaks the encapsulation of a private std::vector<int> items_?
- A std::size_t count() const;
- B std::vector<int>& items(); Correct
- C const std::vector<int>& items() const;
- D std::vector<int> items_copy() const;
Correct Answer: Option B
A non-const reference lets callers add, remove and change items directly, bypassing any validation.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!