what is the advantage of explicit over imolicit in c++

S

sanjaya.swain

Hi,

I have a doubt regarding explicit and implicit declaration in c++.

what is the advantage of explicit over implicit in c++.

is it always better to use explicit ?


Regards
Sanjaya
 
A

aiooua

what is the advantage of explicit over implicit in c++.

single argument constructors may lead to undesirable type-conversions
- see section 11.7.1 from TC++PL for a good example.
the 'explicit' keyword gives you the ability to inform the compiler
when such conversions must not be generated.

there's no 'advantage' of it - only usage.

--
 
J

James Kanze

There is no "advantage" in using one over the other, except perhaps for
implicit conversions reducing typing in your code, because explicit
conversions need to be specified explicitly.

Implicit conversions have several significant effects: they make the
code significantly less readable (except in special cases), and
significantly more error prone. Outside of special cases where
they are part of the idiom (e.g. proxies), they should be
avoided.
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top