implicit casts
James Dennett
jdennett at acm.org
Sat Jul 21 15:05:59 PDT 2007
janderson wrote:
> Ender KaShae wrote:
>> there should be some way to define implicit casts either to or from
>> user defined types. this would greatly reduce the amount of code
>> since functions would no longer have to be overloaded for as many
>> times. ex: a fraction class does not need to overload opAdd since
>> integers can be implictly converted to fractions.
>
> C++ has the copy constructor. Perhaps it should be something along
> those lines. Although the C++ copy constructor is fraught with problems
> because you never know when a conversion may occur.
C++ _copy_ constructors are used for copying, not converting.
Other constructors in C++ are declared "explicit" to disallow
the compiler from using them for implicit conversions, i.e.,
they'll only be used if explicitly requested by code.
-- James
More information about the Digitalmars-d-learn
mailing list