Nulling a reference to a class with opAssign ...
Steven Schveighoffer
schveiguy at yahoo.com
Fri Dec 7 12:12:44 PST 2007
Your exact code compiles for me (dmd 1.0.23)... You sure you are using the
latest dmd?
One observation, your destructor in Foo should not be accessing barRef
because the garbage collector cannot guarantee that the barRef instance
hasn't been collected. If you are in the destructor, there is no reason to
clean up GC references anyways, as the GC will handle that.
-Steve
"Mike" wrote in message
Erm ... this totally catched me off guard ...
class Foo()
{
Bar barRef;
~this() { barRef.noMoreFoo(); }
void opAssign(float f);
}
class Bar()
{
Foo fooRef;
void setFoo(Foo foo) { fooRef = foo; }
void noMoreFoo() { fooRef = null; } // error: can't cast void* to
float ...
}
?
-Mike
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
More information about the Digitalmars-d-learn
mailing list