Re: new vs override - a practical example

Tech-Archive recommends: Speed Up your PC by fixing your registry





jmcgrew@xxxxxxxxx wrote:
> You are casting test to A (at least statically) when you assign it to
> an A variable.

I realize that "without a cast" is a bit ambiguous, I would usually
interpret it as without using the cast operator -- which is the issue here.

< splitting hairs >
Actually I can't find your definition of a cast in ISO/IEC
23270:2003(E). I can find a definition of "implicit conversions" which
captures the above:

* From any class-type S to any class-type T, provided S is derived from T.
* From any class-type S to any interface-type T, provided S implements T.
* From any interface-type S to any interface-type T, provided S is
derived from T.

Although there are a few examples which hints to (unqualified) "cast"
being used the way you specify.
</ splitting hairs >

Claiming that the need to implicitly convert (cast) from a type to
another will help the programmer in any way when using "new" is void.
Implicit conversion is exactly implicit.

In many cases it is not even clear from the immediate context whether an
implicit conversion occurs. Further more, changing a declaration, may
change a situation without implicit conversion to one without, or
vice-versa, and change the semantics of the program -- without so much
as a warning.

BTW: This is also why overloading with sub-classing is so error-prone.

--
Helge Jensen
mailto:helge.jensen@xxxxxxx
sip:helge.jensen@xxxxxxx
-=> Sebastian cover-music: http://ungdomshus.nu <=-
.



Relevant Pages

  • Re: Why is this invalid
    ... is no implicit conversion between 'Test.IDerived1' and 'Test.IDerived2' ... Jon's solution is the correct one, although you don't need to cast ... them both (assuming that IBase is the base interface for both ... IDerived1 and IDerived2). ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C/C++ guidelines
    ... So it's _not_ the usage of the cast which "might introduce ... subtle errors" but forgetting to include. ... Its a warning and no diagnosis is actually required. ... If you rely on getting a useful diagnostic for an implicit conversion ...
    (comp.lang.c)
  • Re: Terminology : casting/conversion
    ... It is certainly more consistent ... to use the phrase "implicit conversion". ... standard defines "cast" as, in effect, "the syntactic construct ... Note that the same sequence of six "int" constants might be used ...
    (comp.lang.c)
  • Re: Terminology : casting/conversion
    ... It is certainly more consistent ... to use the phrase "implicit conversion". ... standard defines "cast" as, in effect, "the syntactic construct ...
    (comp.lang.c)