LearnFrenzy
Sign in Take a free test

Encapsulation · Encapsulation MCQ · Question 9

Which getter breaks encapsulation? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
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&lt;int&gt;&amp; items(); Correct
  • C const std::vector&lt;int&gt;&amp; items() const;
  • D std::vector&lt;int&gt; 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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links