Ace Your C++ Skills 2024 – Rock the ‘Thinking in C++’ Challenge!

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

Question: 1 / 50

What is the purpose of 'static' before a class member function?

To ensure the function can only be called by static objects of the class

To indicate the function is thread-safe

To associate the function with the class as a whole rather than with an instance

Using the keyword 'static' before a class member function allows the function to be associated with the class as a whole, rather than with a specific instance of the class. This means that the function can be called without having to create an instance of the class, making it accessible to all instances. Option A is incorrect because the static keyword does not restrict the function to be called only by static objects. Option B is incorrect because the use of the static keyword does not inherently guarantee thread safety. Option D is incorrect because while a static function can be called without an instance of the class, it does not necessarily serve the main purpose of making the function associated with the class as a whole.

To make the function accessible without an instance of the class

Next

Report this question