extern

class SelfCreator
  '
  int i
  '
  function Object() as SelfCreator
    #ifdef retunvar.___
      ? returnvar = @SelfCreator_table
    #endif
    returnvar.i=1
  end function

  function NewObject() as SelfCreator*
    'returns a new instance
    'can be called from a class or
    'an instantiated object because
    'the method does not refer to 'this'
    new SelfCreator C 
    return @c
  end function
end class

'SelfCreator t=NewObject()
'print t.i
'del t


dim as SelfCreator *obj1, *obj2

'@obj1=SelfCreator.NewObject()    'calling as class method (with dummy 'this')
'@obj2=obj1.NewObject()           'calling as instance method (with real 'this')

'#show let obj3 = SelfCreator.NewObject()
'#recordof obj3
'del obj3

#show {
build SelfCreator obj4()
}
#show let obj5 = obj4.object
print obj5.i

del obj1
del obj2







