Specifies that a constructor or cast function (since C++ 11) is explicit, that is, it cannot be used for implicit casts and copy initialization.
Let’s take an example, you have the following code:
The do_something function takes a parameter of type TerminalRoot, but the compiler automatically converts it to int:
And you don’t want that, you want the correct type to be passed, because you want to know if there is a bug in that type. So you use the explicit keyword, but when compiling there is an error compiling:
And then you get the error:
Cannot convert int to TerminalRoot. So you need to pass the correct type now: do_something( TerminalRoot( 963 ) );