Forcing single-argument constructors to be explicit in C++?

It could be rather nasty for any header you have. Like <vector>, or any of the Boost headers. It would also cause quite a few false bugreports. So, no, I don't expect a compiler to add such a #pragma.


If there was a pragma or command line option that made constructors explicit by default, how would you declare one that is not explicit? There would have to be another compiler-specific token or pragma to make it possible to declare an implicit conversion constructor.


Nope, you have to do it all by hand. It's a pain, but you certainly should get in the habit of making single argument constructors explicit. I can't imagine the pain you would have if you did find a solution and then had to port the code to another platform. You should usually shy away from compiler extensions like this because it will make the code less portable.

Tags:

C++