On Sun, Feb 21, 2010 at 14:34, Michel Fortin <[email protected]>wrote:

> On 2010-02-21 08:28:02 -0500, Philippe Sigaud <[email protected]>
> 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?

Reply via email to