Home What does the explicit keyword mean?
Reply: 0

What does the explicit keyword mean?

user9327
1#
user9327 Published in September 19, 2018, 6:51 pm

What does the explicit keyword mean in C++?

share|improve this question
  • 99
    I just want to point out to anyone new coming along that ever since C++11, explicit can be applied to more than just constructors. It's now valid when applied to conversion operators as well. Say you have a class BigInt with a conversion operator to int and an explicit conversion operator to std::string for whatever reason. You'll be able to say int i = myBigInt;, but you'll have to cast explicitly (using static_cast, preferably) in order to say std::string s = myBigInt;. – chris Aug 30 '12 at 16:52
  • 2
    Can't explicit also refer to assignment? (i.e. int x(5);) – Eitan Myron Feb 27 '14 at 5:10
  • 1
    theunixshell.blogspot.com/2013/01/explicit-keyword-in-c.html – Vijay Apr 19 '14 at 10:43
  • @chris The idea of an explicit implicit conversion is absurd. Stay clear of it! – curiousguy Jun 19 at 20:25
  • @curiousguy, There's no such thing as an explicit implicit conversion. – chris Jun 20 at 14:58

11 Answers 11

active oldest votes
up vote 2804 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.525146 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO