comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: user-defined type conversion
Date: Sun, 19 May 2002 15:58:50 -0500
Date: 2002-05-19T15:58:50-05:00	[thread overview]
Message-ID: <mailman.1021842002.15411.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: bebbba07.0205191029.5db25d0@posting.google.com


----- Original Message ----- 
From: "Russ" <18k11tm001@sneakemail.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: May 19, 2002 1:29 PM
Subject: Re: user-defined type conversion


<snip>
> Type conversion IS a function! It seems to me that I should be able to
> do it the same way it is done for the built-in types (float, integer,
> etc.). C++ allows that nicely.
> 
With all due respect, the word "function" does not appear at all in
section 4.6 (Type Conversions) in the LRM, so I'm not sure one can
truthfully make the blanket statement "Type conversion IS a function!"

Going back to your original code, you had:
type inches is new float;
type feet is new float;

function inches ( arg: feet ) return inches is
    begin
    return inches ( 12.0 * float(feet) );
    end inches;

First, one cannot multiply a type name by a number, so if we assume that
you meant to write
    return inches (12.0 * float(arg));
what we have is an argument of type Standard.Float (the result of the
multiplication) as the argument of a type conversion to the type Inches.

This type conversion differs from a function in that it will accept any
numeric expression (Integer, Float, Fixed, etc.) whereas a function
requires an argument of the specific type with which it was declared.

Thus, the conversion of arg to float is ineffectual in an expression
used as the argument of a type conversion to Inches, since any numeric
expression will do.

Since this is the case, overloading will not work, because an argument
of type feet is _required_ for the function Inches, and is _legal_ for
the type conversion Inches, hence overloading would be ambiguous.

I hope I have clarified the matter -- i.e. why a type conversion is
_not_ a function -- because its argument type is not fixed.






  reply	other threads:[~2002-05-19 20:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-19  7:44 user-defined type conversion Russ
2002-05-19  8:54 ` martin.m.dowie
2002-05-19 10:44 ` David C. Hoos, Sr.
2002-05-19 18:29   ` Russ
2002-05-19 20:58     ` David C. Hoos, Sr. [this message]
2002-05-19 21:12     ` Jeffrey Carter
2002-05-21  9:18       ` Dmitry A. Kazakov
2002-05-19 19:01 ` sk
2002-05-20  3:33   ` Russ
2002-05-20 19:27     ` Randy Brukardt
2002-05-20 19:45       ` David C. Hoos
2002-05-19 21:17 ` Jeffrey Carter
2002-05-20  3:25   ` Russ
2002-05-20  6:21     ` Jeffrey Carter
2002-05-21  9:30       ` Dmitry A. Kazakov
     [not found]     ` <mailman.1021892102.6644.comp.lang.ada@ada.eu.org>
2002-05-20 19:26       ` Russ
2002-05-21  9:35         ` Dmitry A. Kazakov
2002-05-22  4:32         ` Russ
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox