11.4 — Deleting functions

In some cases, it is possible to write functions that don’t behave as desired when called with values of certain types. Consider the following example: #include <iostream> void printInt(int x) { std::cout << x << ‘\n’; } int main() { printInt(5); // okay: prints 5 printInt(‘a’); // prints 97 — …

15.10 — Ref qualifiers

Author’s note This is an optional lesson. We recommend having a light read-through to familiarize yourself with the material, but comprehensive understanding is not required to proceed with future lessons. In lesson , we discussed how calling access functions that return references to data members can be dangerous when the …

14.7 — Member functions returning references to data members

In lesson , we covered return by reference. In particular, we noted, “The object being returned by reference must exist after the function returns”. This means we should not return local variables by reference, as the reference will be left dangling after the local variable is destroyed. However, it is …

13.15 — Alias templates

In lesson , we discussed how type aliases let us define an alias for an existing type. Creating a type alias for a class template where all template arguments are explicitly specified works just like a normal type alias: #include <iostream> template <typename T> struct Pair { T first{}; T …