D
dolphin
Hi all !
What is the 'explicit' mean as a key word? Thank you!
What is the 'explicit' mean as a key word? Thank you!
Hi all !
What is the 'explicit' mean as a key word? Thank you!
Hi all !
What is the 'explicit' mean as a key word? Thank you!
Hi all !
What is the 'explicit' mean as a key word? Thank you!
* dolphin:
Currently it applies to constructors only. A class T constructor of one
argument can by default be called implicitly to convert the argument to
type T. If it's declared "explicit" it cannot be called implicitly: you
have to call it explicitly, writing T(v).
Much of the reason is the lack of named actual arguments in C++. E.g.,
a constructor of one int argument is only seldom meant as a conversion
from int to T: it doesn't produce a T object that in any practical sense
"corresponds" to the int value, yet its usage is the same as a
conversion, a mapping from int to T. Instead of using "explicit" to
avoid implicit conversion you can use any of a number of workarounds for
the lack of named actual arguments, e.g. see the FAQ item titled "What
is the "Named Parameter Idiom"?", currently available at e.g. <url:http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18>.
Possibly the "explicit" syntax will be extended also to operator U()
conversion functions.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
How to use it? And why use it and where use it?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.