Nulling a reference to a class with opAssign ...

Jarrett Billingsley kb3ctd2 at yahoo.com
Fri Dec 7 18:13:34 PST 2007


"Mike" <vertex at gmx.at> wrote in message news:op.t2zshuvdkgfkbn at lucia...
On Fri, 07 Dec 2007 23:25:44 +0100, Frank Benoit
<keinfarbton at googlemail.com> wrote:
-------------------
Ok ... got it:

class Foo(T)
{
T opAssign(T v) { return v; }
}

void main()
{
auto foo = new Foo!(float)();
foo = cast(Foo!(float))null; // Works
foo = null;                  // Error: Can't convert null to float
}

I'm not sure ... but I think the second assignment should work.
-------------------

I absolutely think it should.  It's checking for an opAssign, finding it, 
but not falling back to the default behavior. 




More information about the Digitalmars-d-learn mailing list