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.


Why can't preprocessor macros be used as class member functions?

  1. Macros cannot return a value.

  2. Macros have a different scope than classes.

  3. Macros cannot access private class members due to lack of scoping.

  4. Macros are not supported in C++.

The correct answer is: Macros cannot access private class members due to lack of scoping.

Preprocessor macros are not suitable for use as class member functions because they do not have access to the private members of a class. This is because macros are not scoped within a class, unlike member functions which have access to the class's private members. In addition, macros can be used globally and do not have the same specific scope as classes. While the other options may also be true, they do not fully explain why macros cannot be used as class member functions.