The following list is just a selection.
Specifier | Variable | Function |
---|---|---|
const | Can’t be modified.1 | Method: Can’t modify its fields.1 |
constexp | Calculation happens (if possible) during compile time.2 | |
extern | Global: Can be defined in another translation unit.3 | |
final | Method: Can’t be overridden in a derived class. | |
inline | Code gets inserted at calling spots.4 | |
mutable | Field: Modifiable, even if object is const. | |
noexcept | Shall not throw an exception.5 | |
override | Method: Overrides a virtual method of a base class. | |
static | Field / Method: Part of the class, not the objects. Global: Restricts the visibility to its translation unit. |
|
Local: Stays alive after leaving the scope. | ||
thread_local | Local: Like static, but each thread has its own. | |
virtual | Method: Overridable in inheriting classes. | |
volatile | No compiler optimization allowed.6 |
1 Exception: Fields with mutable
2 Faster run time, slower compile time.
3 Default for non-const vars and funcs.
4 Better performance, larger binary.
5 Else std::terminate() gets executed.
6 Worse performance, always right value.