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.


In C++, what must you not do with inline functions regarding static objects?

  1. Declare them inside the inline function

  2. Use them in inline functions

  3. Define them in every file where the inline function is

  4. None of the above

The correct answer is: Define them in every file where the inline function is

Inline functions in C++ must be declared and defined in every file where they are used. This is because inline functions essentially replace function calls with the function's code, and having multiple definitions in different files can lead to conflicts. Option A is incorrect because declaring a static object inside an inline function would actually make it local to that function, defeating the purpose of a static object which is to retain its value even after the function is completed. Option B is incorrect because using static objects in inline functions is allowed, as long as they are declared and defined only once. Option D is incorrect because as mentioned, inline functions and static objects are allowed to be used together, as long as they are defined correctly.