Talk:cpp/language/explicit

static_cast
It should be used either or  in both A and B examples. I think makes it more readable, is there any reason to use ? -- Bazzy 15:07, 13 March 2012 (PDT)


 * C-style cast is too generic to be useful (except when you're implementing or ). Especially when the purpose is to explain something. Editing to static cast --Cubbi 19:02, 13 March 2012 (PDT)

structures without member variables
Is there a reason the structs in the examples do not have member variables? Does it make it a better example? Arbalest 14:47, 14 December 2012 (PST)


 * It's to keep the example as minimal as possible. The definition of the structs is not really relevant.
 * The example is there just to show what would compile and what not.
 * --Bazzy 15:05, 14 December 2012 (PST)

Multiple arguments
explicit on a constructor with multiple arguments has no effect, since such constructors cannot take part in implicit conversions. However, for the purpose of implicit conversion, explicit will have an effect if a constructor has multiple arguments and all but one of the arguments has a default value.
 * wouldn't it be simpler to say that it has no effect on constructors that aren't converting constructors? --Cubbi (talk) 13:53, 22 September 2014 (PDT)
 * having looked at it, that would've been a tautology: converting constructors are defined as non-explicit constructors, regardless of the number of non-default arguments. --Cubbi (talk) 17:01, 22 September 2014 (PDT)

template constructors can be explicit too
Not sure how useful such information, but template constructors can be explicit too, e.g.

AFAIK such constructor will match any argument, e.g. C(5.0) or C(std::string) making no sense to specify "explicit".


 * certainly, both constructors (other than copy/move) and user-defined conversion functions may be function templates (I added a line). This has no special effect on the meaning of ; an explicit template constructor will not be considered in copy-initialization, just like how an explicit non-template constructor isn't: would not compile. --Cubbi (talk) 07:42, 18 December 2014 (PST)


 * Oh, I should sleep more! You right, of course template or not "explicit" specifier meaning doesn't change Rutsky (talk) 12:57, 18 December 2014 (PST)

example improvement
Should we add situations in which the struct A or B is contextually-convertible-to-bool, to the example? Just like that of I/O Streams.


 * That to save this problem. --LittleFlower (talk) 23:36, 31 January 2018 (PST)