Some questions now D2 is frozen

Philippe Sigaud philippe.sigaud at gmail.com
Sun Feb 21 05:56:14 PST 2010


On Sun, Feb 21, 2010 at 14:34, Michel Fortin <michel.fortin at michelf.com>wrote:

> On 2010-02-21 08:28:02 -0500, Philippe Sigaud <philippe.sigaud at gmail.com>
> said:
>
>  Another thing I'd be very happy to have is opImplicitCast....
>>
>
> I think this works already:
>
>        alias opImplicitCast this;
>
>        @property T opImplicitCast() { ... } <http://michelf.com/>


Hmm, I'm still a bit leery of 'alias this' as all my uses for it misfired.
But if that works, then, being an obnoxious brat, I will ask for the
possibility to have many 'alias this' in the same object :-)

Anyway, I just tried:

class C {

   alias opImplicitCast this;

   @property int opImplicitCast() { return 1;}
}

auto c = new C();
int foo(int a) { return a;}

foo(c); // error. function main.foo (int a) is not callable using argument
types (C)
auto i = cast(int)c; // This works, but I'd call that explicit cast...

I'm doing something wrong there? Is calling foo on c an implicit cast?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100221/501135c8/attachment.html>


More information about the Digitalmars-d mailing list