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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sanjaya.swain@gmail.com

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

    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
  • aiooua

    #2
    Re: what is the advantage of explicit over imolicit in c++

    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.

    --

    Comment

    • Kevin Frey

      #3
      Re: what is the advantage of explicit over imolicit in c++

      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.

      My strategy is to generally start off with conversions being implicit and if
      certain conversions start "getting in the way" when you don't want them to,
      then I consider making them explicit.


      Comment

      • James Kanze

        #4
        Re: what is the advantage of explicit over imolicit in c++

        On Aug 6, 2:07 am, "Kevin Frey" <kevin_g_f...@h otmail.comwrote :
        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.

        --
        James Kanze (GABI Software) email:james.kan ze@gmail.com
        Conseils en informatique orientée objet/
        Beratung in objektorientier ter Datenverarbeitu ng
        9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

        Comment

        • Greg Comeau

          #5
          Re: what is the advantage of explicit over imolicit in c++

          In article <3Iqdnb-748mjdgXVnZ2dnU VZ_v_inZ2d@post ed.internode>,
          Kevin Frey <kevin_g_frey@h otmail.comwrote :
          >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.
          >
          >My strategy is to generally start off with conversions being implicit and if
          >certain conversions start "getting in the way" when you don't want them to,
          >then I consider making them explicit.
          That's actually tending to be the exact opposite reason for 'explicit'.
          This also lends to the concern how do you know the conversions are
          getting in the way if they are implicit. :) An aspect of explicit
          is to make you think about the conversions.
          --
          Greg Comeau / 4.3.10.1 with C++0xisms now in beta!
          Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
          World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
          Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

          Comment

          Working...