Introducing static classes
The static
class concept that we will discuss here doesn’t exist in the C++ language standard. We are borrowing it from languages such as C#, where it is defined as a class that contains only static
members and methods. It can’t be instantiated. In C#, a static
class is declared using the static
keyword.
In C++, a static
class can be created by defining a class with all static
methods and members and by deleting the default constructor. Deleting the constructor ensures that no instances of the class can be created, enforcing this at compile time. Disabling instantiation signals a clear intent to the user: This is a static
class. The functions you’re using don’t rely on any instance-specific states, as no instances exist. If there’s any internal state, it’s shared and will affect everyone using the class.
We will modify the previous example and create a uart_c_hal
static
class to wrap UART C HAL functions...