General topics | ||||||||||||||||
Flow control | ||||||||||||||||
Conditional execution statements | ||||||||||||||||
Iteration statements (loops) | ||||||||||||||||
Jump statements | ||||||||||||||||
Functions | ||||||||||||||||
Function declaration | ||||||||||||||||
Lambda function expression | ||||||||||||||||
inline specifier | ||||||||||||||||
Dynamic exception specifications(until C++17*) | ||||||||||||||||
noexcept specifier(C++11) | ||||||||||||||||
Exceptions | ||||||||||||||||
Namespaces | ||||||||||||||||
Types | ||||||||||||||||
Specifiers | ||||||||||||||||
| ||||||||||||||||
Storage duration specifiers | ||||||||||||||||
Initialization | ||||||||||||||||
Expressions | ||||||||||||||||
Alternative representations | ||||||||||||||||
Literals | ||||||||||||||||
Boolean -Integer -Floating-point | ||||||||||||||||
Character -String -nullptr(C++11) | ||||||||||||||||
User-defined(C++11) | ||||||||||||||||
Utilities | ||||||||||||||||
Attributes(C++11) | ||||||||||||||||
Types | ||||||||||||||||
typedef declaration | ||||||||||||||||
Type alias declaration(C++11) | ||||||||||||||||
Casts | ||||||||||||||||
Memory allocation | ||||||||||||||||
Classes | ||||||||||||||||
Class-specific function properties | ||||||||||||||||
| ||||||||||||||||
Special member functions | ||||||||||||||||
Templates | ||||||||||||||||
Miscellaneous | ||||||||||||||||
Declarations | ||||
Function declaration | ||||
Function parameter list | ||||
Function definition | ||||
Function contract specifiers(C++26) | ||||
Default arguments | ||||
Variadic arguments | ||||
inline specifier | ||||
Lambda expressions(C++11) | ||||
Coroutines(C++20) | ||||
Replacement functions | ||||
Function calls | ||||
Argument-Dependent Lookup (ADL) | ||||
Function-call operator | ||||
Function objects | ||||
Overloading | ||||
Overload resolution | ||||
Operator overloading | ||||
Address of an overload set |
Certain functions for which a definition is supplied by the implementation arereplaceable . A C++ program may provide a definition with thesignature of a replaceable function, called areplacement function . The replacement function, if provided, is used instead of the default version supplied by the implementation. Such replacement occurs prior to program startup.
If a declaration of the replacement function does not satisfy any of the following conditions, the program is ill-formed, no diagnostic is required:
Core languageIt is implementation-defined whether thecontract-violation handler::handle_contract_violation is replaceable. | (since C++26) |
The following standard library functions are replaceable, and the description of function semantics apply to both the default version defined by the C++ standard library and the replacement function defined by the program:
allocation functions (function)[edit] | |
deallocation functions (function)[edit] | |
(C++26) | checks whether a program is running under the control of a debugger (function)[edit] |
Uses a replacement allocation function:
#include <cstddef>#include <new>#include <print> // replacement functionvoid*operator new(std::size_t count){std::print("Replaced!");return nullptr;} int main(){int* ptr= newint;// invokes the replacement version defined by the program}
Output:
Replaced!