digitalmars.D.learn - Is it possible to set this on null?
- Zarathustra (13/13) Aug 06 2008 class CFoo{
- BCS (4/16) Aug 06 2008 that doesn't work because this is a hidden arg to the function, you can ...
- Koroskin Denis (2/18) Aug 06 2008
- Zarathustra (3/24) Aug 06 2008 Reply to BCS,
class CFoo{ public void destroy(){ delete this; } // ok public void forget(){ this = null; } // ok but no effect } void main(){ auto l_fooA = new CFoo; auto l_fooB = l_fooA; l_fooA.forget; // no effect l_fooA = null; // now ok l_fooB.destroy; // ok }
Aug 06 2008
Reply to Zarathustra,class CFoo{ public void destroy(){ delete this; } // ok public void forget(){ this = null; } // ok but no effect }that doesn't work because this is a hidden arg to the function, you can change its value but as with any other local value that doesn't effect the value used to call the function.void main(){ auto l_fooA = new CFoo; auto l_fooB = l_fooA; l_fooA.forget; // no effect l_fooA = null; // now ok l_fooB.destroy; // ok }
Aug 06 2008
On Wed, 06 Aug 2008 22:05:48 +0400, BCS <ao pathlink.com> wrote:Reply to Zarathustra,In fact, this should be disallowed (and it is in c++).class CFoo{ public void destroy(){ delete this; } // ok public void forget(){ this = null; } // ok but no effect }that doesn't work because this is a hidden arg to the function, you can change its value but as with any other local value that doesn't effect the value used to call the function.void main(){ auto l_fooA = new CFoo; auto l_fooB = l_fooA; l_fooA.forget; // no effect l_fooA = null; // now ok l_fooB.destroy; // ok }
Aug 06 2008
BCS Wrote:Reply to Zarathustra,Reply to BCS, Ok thanks for explain it. All regards!class CFoo{ public void destroy(){ delete this; } // ok public void forget(){ this = null; } // ok but no effect }that doesn't work because this is a hidden arg to the function, you can change its value but as with any other local value that doesn't effect the value used to call the function.void main(){ auto l_fooA = new CFoo; auto l_fooB = l_fooA; l_fooA.forget; // no effect l_fooA = null; // now ok l_fooB.destroy; // ok }
Aug 06 2008