[CPP] - ECX register is used for object pointer.


class Base
{
public:
  Base()
  {
    foo(); mov ecx,dword ptr [this] // ecx <- object pointer
           call Base::foo (4111A9h) // direct call
  }
  virtual void foo() {
  } 
};



[Pascal] - EAX register is used for object pointer.


Base = class

public
  constructor Create;
  destructor Destroy; override;
  procedure foo; virtual;
end;

constructor Base.Create;
begin
  foo; mov eax,esi          // eax <- object pointer
       mov edx,[eax]        // edx <- virtual method pointer table 
       call dword ptr [edx] // indirect call(first virtual method pointer)
end;



In constructor code in C++, even if a function is declared as virtual, the function is called in direct mode(not indirect mode) because virtual table of that object is not set yet. So does in destructor codes.


[Download]

virtual_test.zip