Sign in to follow this  
hymerman

C++: Should I bother using 'explicit' for constructors with multiple arguments?

Recommended Posts

It may have no effect, but what if later in development arguments are removed or given default values by somebody who doesn't know when to use 'explicit'? Should I bother making constructors explicit when they accept multiple arguments even though all it serves is to add 9 characters to the source?

Share this post


Link to post
Share on other sites
Personally I'd say not. If someone changes the constructor at some later time it should be their responsibility to decide whether it should then be marked explicit, not your responsibility to second-guess their work in advance. Plus, changes to the public interface, including construction, will have an impact on client code, so it seems more likely that someone might later write a new overloaded constructor rather than change the existing interface.

Share this post


Link to post
Share on other sites
If for some horrible reason you had to write a code generator or something, I would say "sure, go ahead, mark everything as 'explicit' in the generated code". But otherwise, no. Like PKLoki said, it should be the responsibility of the person changing the code, at that point. YAGNI and all that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this