C++

General Tips

  • Difference between constexpr and const

    • const prevents variables from being modified, constexpr tells the compiler that an expression results in a compile-time constant

    • Only values known at compile time can be assigned to constexpr

    • When applied to functions, const can only be used for non-static member functions

      • Guarentees the member function does not modify any non-static data members

    • constexpr can be used with member and non-member functions

      • Declares function fit for use in constant expressions

      • Arguments and return types must be literal types

Last updated