Sections[lang]

Language

The core language as it is written now, from values and moves to lambdas and modules, for developers who learned C++ once and need the current answer.

Clause
1 of 8
Answers
4, newest first
Written for
C++11, C++20
Written by

Much of what you write on every line has been reworked since C++03: how values are passed, moved and returned, what the compiler writes for a class, what auto deduces. This section covers those rules for the standard you compile with. Start with what std::move and && really do, then the special members C++ writes for you and when to write none of them. Since C++11 a throwing destructor calls std::terminate; can a C++ destructor throw covers what noexcept(false) changes.

In this section

  • Value semantics and passing arguments
  • Move semantics and rvalue references
  • Copy elision and returning values
  • Special member functions and the rule of zero
  • Lambdas and closures
  • Type deduction with auto and decltype
  • const, constexpr and consteval
  • Exceptions, noexcept and error handling
  • References, pointers and lifetimes
  • Classes, inheritance and polymorphism
  • Initialization rules
  • Modules and headers

Answers in Language 4, newest first

  1. Can a C++ destructor throw? What happens since C++11

    Since C++11 a throwing destructor calls std::terminate. What noexcept(false) changes, why containers forbid it, and how to report failure from close().

    §1.19 min readC++20

    written for C++20

  2. C++ virtual functions: override, pure virtual and the traps

    How a C++ virtual function call is resolved, why to write override and a virtual destructor, pure virtual functions, and which warnings catch the traps.

    §1.29 min readC++11

    written for C++11

  3. C++ move semantics: what std::move and && really do

    What a move is, why std::move moves nothing, what C++17, C++20 and C++23 changed about temporaries and returns, and four move mistakes clang-tidy catches.

    §1.317 min readC++20

    written for C++20

  4. Rule of zero: the special members C++ writes for you

    Which special member functions C++ declares for a class, what declaring one does to the others, and when to write none, all five, or delete them.

    §1.413 min readC++20

    written for C++20