This has nothing to do with type safety, both examples are safe.
When creating a language, you need to determine what is allowed and what is not. Since writing a blacklist will be an endless experience, the language is usually written in white list style, adding more and more things.
However, things cannot be allowed without a clear weighting of the consequences. Whenever you want to allow something new, you need to check:
- ease of implementation
- interaction with other existing functions and known probable extensions
In addition, this also means that for those who want to use the language, you can learn more.
What you ask for here, however, is relatively easy. It can be thought of as an instance of a class, for default arguments. This was adopted in C ++ 11 because it was the easiest way to ensure that the default values ββare consistent when writing multiple constructors.
Personally, when using C ++ 11, I recommend initializing all built-in types this way (only to 0 ), just as I recommend initializing them when declaring local variables: this way you cannot forget to initialize them in one of the constructors.
source share