Topic: explicit and casts


Author: shepherd@debussy.sbi.com (Marc Shepherd)
Date: 1995/06/22
Raw View
In article KDq@netcom.com, smeyers@netcom.com (Scott Meyers) writes:
>Section 12.3 of the draft C++ standard contains:
>
>  2 A  nonconverting  constructor  constructs objects just like converting
>    constructors, but does so only where a constructor call is  explicitly
>    indicated by the syntax....[examples elided]
>
>  Z a4 = (Z)1;               // ok?
>  Z a5 = static_cast<Z>(1);  // ok?

Funny you should ask.  My reading of the text leads me to believe that
neither of the examples above would work, since no "constructor call
is explicitly indicated by the syntax."

However, I agree with Scott that, regardless of the resolution, the
draft is ambiguous on this point and should be clarified.

---
Marc Shepherd
Salomon Brothers Inc
shepherd@schubert.sbi.com The opinions I express are no one's but mine!






Author: ncm@netcom.com (Nathan Myers)
Date: 1995/06/20
Raw View
In article <smeyersDAFvH2.KDq@netcom.com>,
Scott Meyers <smeyers@netcom.com> wrote:
>Section 12.3 of the draft C++ standard contains:
>
>  2 A  nonconverting  constructor  constructs objects just like converting
>    constructors, but does so only where a constructor call is  explicitly
>    indicated by the syntax.  [Example:
            struct Z {  explicit Z(int);  /* ... */  };
> ... What about these?
>
>  Z a4 = (Z)1;               // ok?
>  Z a5 = static_cast<Z>(1);  // ok?
>
>I would expect the first of these to be valid, as I'm under the
>impression that the following cast forms are semantically identical:
>
>  (type)expression
>  type(expression)

The original proposal had an example allowing the "(Z)1" form.
Does the WP correctly reflect it?

Nathan Myers
myersn@roguewave.com





Author: smeyers@netcom.com (Scott Meyers)
Date: 1995/06/19
Raw View
Section 12.3 of the draft C++ standard contains:

  2 A  nonconverting  constructor  constructs objects just like converting
    constructors, but does so only where a constructor call is  explicitly
    indicated by the syntax.  [Example:
            class Z {
            public:
                    explicit Z(int);
                    // ...
            };
            Z a1 = 1;        // error: no implicit conversion
            Z a3 = Z(1);     // ok: explicit use of constructor
            Z a2(1);         // ok: explicit use of constructor
            Z* p = new Z(1); // ok: explicit use of constructor
     --end example]

What about these?

  Z a4 = (Z)1;               // ok?
  Z a5 = static_cast<Z>(1);  // ok?

I would expect the first of these to be valid, as I'm under the
impression that the following cast forms are semantically identical:

  (type)expression
  type(expression)

That being the case, however, I'd also expect the form using
static_cast to be valid.

Anybody know what's supposed to happen?

Thanks,

Scott