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.


How does defining an operator as a global function differ from as a member function in terms of argument count?

  1. Global functions require an explicit 'this' pointer as an argument

  2. Global functions take one more argument than member functions for binary operators

  3. Member functions always take two arguments regardless of the operator type

  4. There is no difference in argument count between global and member function operators

The correct answer is: Global functions take one more argument than member functions for binary operators

When defining an operator as a global function, the function takes one more argument than when defined as a member function for binary operators. This is because global functions do not have access to the object's "this" pointer, so they need an additional parameter to explicitly pass in the object's data. Member functions, on the other hand, automatically have access to the "this" pointer and therefore do not require an extra argument. This extra argument may be the reason why global functions are sometimes preferred over member functions, as they allow for more flexibility in the types of objects on which the operator can be applied. Choices A and C are incorrect because they do not accurately describe the difference in argument count between global and member function operators. Choice D is incorrect because, as explained, there is indeed a difference in argument count between the two.