User-Defined Literals
Explore user-defined literals in C++ and understand how adding suffixes to built-in literals allows for type-safe arithmetic and clearer code. This lesson covers syntax changes from C++11 to C++14, showing how to implement and use custom literal operators to combine values with units effectively, a key skill for safety-critical software development.
We'll cover the following...
We'll cover the following...
User-defined literals are a unique feature in all mainstream programming languages. They empower us to combine values with units.
With C++11, it’s possible to generate user-defined literals by adding a suffix to a built-in literal for integers, floating points, characters, and C strings.
Syntax #
User-defined literals must obey the following syntax:
Usually, we use the suffix for a unit: