Third standard attribute
Explore the [[nodiscard]] attribute introduced in C++17, which helps ensure important function return values are used. Understand how it applies to functions and types to improve error handling and prevent bugs, and see how it is extended in C++20.
We'll cover the following...
We'll cover the following...
The third standard attribute we get in C++17 is:
[[nodiscard]] attribute
[[nodiscard]] can be applied on a function or a type declaration to mark the importance of the
returned value:
The above code should emit a warning when you compile it as you haven’t assigned the result to a variable.
What it means is that you can force users to handle errors. For example, what happens if you forget
about using the return value from new or ...