Mastering C++: A Comprehensive Quiz Based on 'Thinking in C++'

Disable ads (and more) with a membership for a one time $2.99 payment

Test your C++ skills with our quiz based on Bruce Eckel's 'Thinking in C++'. Dive into object-oriented programming, advanced topics, and fundamentals. Perfect for learners and experts alike. Assess your knowledge and become a C++ master!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


Which of the following is a guideline for overloading operators in C++?

  1. Overload as many operators as possible to ensure full coverage

  2. Only overload operators where it enhances readability and usability of the class

  3. Prefer global overloading to member function overloading for arithmetic operators

  4. Always return objects by value to ensure encapsulation

The correct answer is: Only overload operators where it enhances readability and usability of the class

The guideline for overloading operators in C++ is to only overload operators where it enhances readability and usability of the class. Option B is the correct answer because overloading too many operators can make code confusing and difficult to understand. Option A may lead to unnecessary overloading and bloated code. Option C is incorrect because member function overloading should be preferred over global overloading for arithmetic operators for better encapsulation. Option D is also incorrect because returning objects by value may lead to shallow copies and potential issues with encapsulation. Therefore, B is the best guideline for overloading operators in C++.