this pointer

Zarathustra adam.chrapkowski at gmail.com
Wed Oct 21 13:53:20 PDT 2009


Why value of pointer to this is different in global function, member function and constructor?
//---------------------------------------------------------------------------------------------------
module test;
class Foo{
  this(){
    writefln("ctor 0x%08X", cast(dword)&this);
  }

  void func(){
    writefln("func 0x%08X", cast(dword)&this);
  }
}
import std.stdio;

void main(){
    Foo foo = new Foo;
    writefln("main 0x%08X", cast(dword)&foo);
    foo.func();    
}
//---------------------------------------------------------------------------------------------------
sample output:
ctor 0x0012FEC8
main 0x0012FEE8
func 0x0012FEB8


More information about the Digitalmars-d-learn mailing list