|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D.learn - opAssign: cannot set reference of object to null
Hi,
in the following code the statement "b = null" calls "B opAssign( A v )" and
causes an access violation. I don't understand why! How can I set b to null?
I'm using dmd 1.028.
class A
{
this( int i )
{
a = i;
}
int a;
}
class B
{
this( int i )
{
a = i;
}
int a;
B opAssign( A v )
{
a = v.a;
return this;
}
}
int main(char[][] args)
{
A a = new A( 4 );
assert( a.a == 4 );
B b ;
assert( b is null );
b = new B( 5 );
b = a;
assert( b.a == 4 );
b = null;
assert( b is null );
}
Apr 21 2008
Mahe wrote:in the following code the statement "b = null" calls "B opAssign( A v )" and causes an access violation. I don't understand why! How can I set b to null? I'm using dmd 1.028. Apr 21 2008
"Mahe" wrote Apr 21 2008
|