C++ - Functions
Last Updated: 2022-02-12
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
- 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)
constevalfunctions / immediate functions (C++20)
finalfor virtual functions (C++11)
= deletefunctions (C++11)
- lambdas (C++11)
- coroutines (C++20)
Use lambda expressions as anonymous functors.