In C++ prefixing the explicit keyword to the constructor prevents the compiler from using that constructor for implicit conversions.
In C++, the compiler is allowed to make one implicit conversion to resolve the parameters to a function. What this means is that the compiler can use single parameter constructors to convert from one type to another in order to get the right type for a parameter.
Prefixing the explicit
keyword to the constructor prevents the compiler from using that constructor for implicit conversions.
The reason you might want to do this is to avoid accidental construction that can hide bug.
References: