DEV Community

Discussion on: Avoid C++ implicit conversions from bool

Collapse
 
sdryds profile image
Stewart Smith • Edited

I would say that in the modern C++ paradigm, implicit conversions are generally considered to be bad. That's why there is a big push for explicit single argument constructors. I think you've stumbled upon one if the many oddities of the language that have been grandfathered in by necessity rather than chosen willingly. It's the need for backwards compatiblity that has driven so many seemly insane decisions.

Personally I try to provide a type for every data concept in my program. I use the type_safe strong_types library instead of type aliasing for anything that would be a built in type. That way I get no implicit conversions and bring in additional checks from the type system.