Replacement for C++ Style Implicit casts?

Simen kjaeraas simen.kjaras at gmail.com
Mon Oct 18 15:21:38 PDT 2010


Mike Chaten <mchaten at gmail.com> wrote:

> I was under the impression that alias this just was shorthand for
> Class Foo {
> int x;
> alias x this;
> }
> Foo foo =  new Foo
> foo = 9; // foo.x = 9
> Foo Foo = 9 // null.x =9;

Not just. this would also work:

int n = foo;
// void bar( int n ) {}
bar( foo );


> Also, for opCast, doesnt that only work for going from Foo to int and not
> the other way around?

Indeed. For implicit casts to Foo, I don't know what, if anything, works.

void baz( Foo f ) {}
baz( 3 ); // How?

Likely, there is no such functionality in D, at least for the moment.

-- 
Simen


More information about the Digitalmars-d-learn mailing list