7.10 — Sharing global constants across multiple files (using inline variables)

In some applications, certain symbolic constants may need to be used throughout your code (not just in one location). These can include physics or mathematical constants that don’t change (e.g. pi or Avogadro’s number), or application-specific “tuning” values (e.g. friction or gravity coefficients). Instead of redefining these constants in every …

7.6 — Internal linkage

In lesson , we said, “An identifier’s linkage determines whether other declarations of that name refer to the same object or not”, and we discussed how local variables have no linkage. Global variable and functions identifiers can have either internal linkage or external linkage. We’ll cover the internal linkage case …

20.7 — Lambda captures

In the previous lesson (), we introduced this example: #include <algorithm> #include <array> #include <iostream> #include <string_view> int main() { std::array<std::string_view, 4> arr{ “apple”, “banana”, “walnut”, “lemon” }; auto found{ std::find_if(arr.begin(), arr.end(), [](std::string_view str) { return str.find(“nut”) != std::string_view::npos; }) }; if (found == arr.end()) { std::cout << “No nuts\n”; …

20.6 — Introduction to lambdas (anonymous functions)

Consider this snippet of code that we introduced in lesson : #include <algorithm> #include <array> #include <iostream> #include <string_view> // Our function will return true if the element matches bool containsNut(std::string_view str) { // std::string_view::find returns std::string_view::npos if it doesn’t find // the substring. Otherwise it returns the index where …

0.12 — Configuring your compiler: Choosing a language standard

With many different versions of C++ available (C++98, C++03, C++11, C++14, C++17, C++20, C++23, etc…) how does your compiler know which one to use? Generally, a compiler will pick a standard to default to. Typically the default is not the most recent language standard — many default to C++14, which …