1
const, static and inline
C++
- const — value cannot change after initialisation. A
constmember function cannot modify the object. - static local variable — keeps its value between function calls.
- static member — one copy shared by all objects of the class.
- inline — asks the compiler to paste the function body at the call site to avoid call overhead (for small functions).
void counter() {
static int count = 0; // initialised only once
count++;
cout << count << " ";
}
// counter(); counter(); counter(); → 1 2 3