I have a parent object with no constructor here. But of course in some cases there could be some need for a constructor. Anyway my question is simply a question of efficiency about how to intitialize the parent object of an inherited object (child contains parent so this part of the child has to be initialized somehow).
I have 4 versions here below that for me looks absolutely the same. Maybe however some of this is faster and so on. Maybe there is even another way like the use of the operator LET, I don't know.
Any opinion?
Code: Select all
type PARENT
'declare constructor()
as integer dummyparentvariable
end type
'constructor PARENT()
'
'end constructor
type CHILD extends PARENT
declare constructor()
declare constructor(as PARENT)
declare constructor(as PARENT ptr)
as integer dummychildvariable
end type
constructor CHILD()
'BASE()
'
end constructor
constructor CHILD(byref P as PARENT)
cast(PARENT, THIS) = P
'
end constructor
constructor CHILD(byval Pptr as PARENT ptr)
*cptr(PARENT ptr, @THIS) = *Pptr
'
end constructor
'test
dim as PARENT p
P.dummyparentvariable = 999
dim as CHILD c = CHILD(p)
c.dummychildvariable = 7
? "par0"; c.dummyparentvariable
? "chi0"; ; c.dummychildvariable
dim as CHILD c1 = CHILD(@p)
c1.dummychildvariable = 71
? "par1"; c1.dummyparentvariable
? "chi1"; c1.dummychildvariable
dim as CHILD c2 = CHILD(type<PARENT>(888))
c2.dummychildvariable = 72
? "par2"; c2.dummyparentvariable
? "chi2"; c2.dummychildvariable
dim as CHILD c3 = CHILD(@type<PARENT>(-888))
c3.dummychildvariable = 73
? "par3"; c3.dummyparentvariable
? "chi3"; c3.dummychildvariable
sleep