Namespaces
Variants
Views
Actions

Talk:cpp/language/explicit

From cppreference.com

[edit] static_cast

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

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

[edit] 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)

[edit] 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)