Modern C++

TBD. Including "who added all those c++ versions anyways?", "isn't it just becoming python" and other less-nonsensical points and discussions. Includes reminders on working with floating point values and subsequent comparisons. Usefulness of namespaces, and trying to find functions. And how to work with templates.

Also, as always, review pointers vs. references, how to pass items into a functions, how to return items from a function, how what types of data to store in an object. std::unique_ptr, shared pointers, pImpl pattern.





Misc C++ Knowledge

Example sources:

  • Can we have a recursive inline function in C++?
    • A. Its possible, and a compiler with a good optimizer will generate code to some depth at compile-time, and insert non-recursive calls when actual depth exceeds runtime. Not all compilers are able to do this though, as it can't determine the depth of recursion at compile time.
  • What is a volatile variable?
    • The volatile keyword indicates the compiler should not optimize this variable away. This is important in cases where its not obvious/visible to the compiler that this variable is used outside its common scope. Discussion found here.
  • ++itr vs itr++
    • itr++ is more expensive than ++itr because itr++ creates a copy (for use by code) before incrementing and then returns the copy. Whereas ++itr can increment and then use the original directly in the code. "Most compilers will automatically optimize itr++ to ++itr" eg. in for loops). (Source).
    • Note: Since C++11, just use range-based for loops instead: for (const auto& itr : vec)
  • What is a mutable variable?
    • Can only be applied to non-static and non-constant member variables.
    • Indicates that member variable for a class can be changed, even if object of that class is declared as const, including when used in one of the class's const functions.

BlogIt Side bar

Recently Written

erika: end hiding comments and categories

erika: end hiding comments and categories

Group-Specific Sidebar

Blix theme adapted by David Gilbert, powered by BlogIt