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
- 37, newest first
- Page
- 1 of 4
- Written for
- C++11, C++17
- Written by
- Miriam Castellanos
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
autoanddecltype const,constexprandconsteval- Exceptions,
noexceptand error handling - References, pointers and lifetimes
- Classes, inheritance and polymorphism
- Initialization rules
- Modules and headers
Answers in Language 37, newest first
assert in C++: how assert and
static_assertworkassert in C++ explained: what a failed assert prints, how to add a message, how NDEBUG turns it off, and how
static_assertchecks at compile time.written for C++17
bool in C++: true, false and how to use them
bool in C++ explained: true and false, what produces a bool, why cout prints 1 or 0, what converts to bool, bool functions and the common mistakes.
written for C++17
const in C++: variables, pointers, references, methods
What const means in C++ on a variable, a pointer, a reference and a member function, with the error the compiler gives for each, and const vs constexpr.
written for C++17
constexpr in C++: variables, functions and static constexpr
What constexpr means in C++: constexpr variables and functions, constexpr vs const, static constexpr in a class and inline constexpr in a header.
written for C++17
C++ array: declare, initialize and get the length
How to declare and initialize a C++ array, loop over it, get its length with
std::size, why sizeof fails in a function, andstd::arrayvs vector.written for C++17
C++ class: how to define one and create objects
C++ class explained with one Account example: private data, public functions, objects, a constructor, const member functions, header files, class vs struct.
written for C++17
C++ constructor: default, parameterized, copy and move
What a C++ constructor is and how to write one: default, parameterized, copy and move constructors, the initializer list, explicit and structs.
written for C++11
continue in C++: skip to the next loop iteration
continue in C++: where each loop goes next, why a while loop with continue never ends, continue vs break, nested loops and switch.
written for C++17
Data types in C++: int, double, char, bool and more
The C++ data types in one table: what int, double, char and bool hold, their sizes and ranges, how to check them with sizeof, and which one to use.
written for C++17
C++ do while loop: syntax, examples and do while vs while
The C++ do while loop: its syntax and semicolon, do while vs while, a menu and an input check that survive a letter, and how break and continue behave.
written for C++17