C++ - Functions
non-member functions vs member functions
- non-member functions, a.k.a. free functions: do not belong to any class.
- member functions, a.k.a. methods(but "method" is not used in the C++ standard): part of a class or a struct.
Types of functions
- overloaded functions
static
functionsinline
functions- operators
const
member functionsvirtual
member functions- special class functions: default constructor, copy constructor, copy assignment operator, destructor; (since C++11) move constructor, move assignment operator
- function templates
- pure virtual function (
= 0
): subclasses have to implement this function, otherwise they are abstract. E.g.virtual std::string ToString( ) = 0;
- variadic function templates (C++11)
constexpr
functions (C++11)consteval
functions / immediate functions (C++20)override
andfinal
for virtual functions (C++11)= default
and= delete
functions (C++11)- lambdas (C++11)
- coroutines (C++20)
Lambda
Use lambda expressions as anonymous functors.