Fighting with alias this: bugs or features?
trx1
trx1 at nomail.com
Wed Oct 27 06:38:58 PDT 2010
osa Wrote:
> On 10/26/2010 05:09 PM, Andrei Alexandrescu wrote:
> > Thanks. Defining opAssign for Bar will allow you to use the syntax bar =
> > null and have it nullify the reference.
>
> I feel stupid, but I do not see how to nullify the Bar reference inside
> of opAssign. Again, my problem is that I have
> Bar x = new Bar( ... );
> and I want x to become null. Is there a workaround for 'cannot
> implicitly convert expression (null) of type void* to Foo' which does
> not involve low-level trickery like *cast(void**)&x = null?
A workaround is maybe
struct Foo {}
class Bar {
Foo foo_;
alias foo_ this;
}
void main() {
auto a = new Bar;
auto b = a;
a = a.init; //compiles as oppose to a = null;
writeln(a); // prints null
}
just playing around with the code, so have no explaination for the behaviour
More information about the Digitalmars-d
mailing list