fxm wrote:
Code: Select all
Var Byref B = A '' or Dim Byref B As myUdt = A
Print B.a, B.b, B.fs
Hi all,
@fxm, it's also what I tend to name "clone", but I guess it's something inherited from VB somehow where Classes are byref stuff.
Anyway, there is something else that I want to ask, that completes the question.
In the exemple below, we see that the copy obtained by assignation copies also the pointer value.
Code: Select all
#macro _P(expression)
? #expression, expression
#endMacro
type UDT
declare constructor()
declare destructor()
as integer _dummyInsideValue
as any ptr _dummyInsideReference
end type
constructor UDT()
THIS._dummyInsideValue = 111
THIS._dummyInsideReference = allocate(1)
end constructor
destructor UDT()
deallocate THIS._dummyInsideReference
end destructor
dim as UDT uu1
_P(uu1._dummyInsideReference)
dim as UDT uu2 = uu1
_P(uu2._dummyInsideReference)
sleep
Code: Select all
uu1._dummyInsideReference 13904352
uu2._dummyInsideReference 13904352
We don't have first a new ALLOCATE (or constructor call), and then a copy of the value pointed in the new allocated pointer.
If it did, it would be a DEEP CLONING, according to this page
https://www.codeproject.com/Articles/46 ... cts-in-NET.
Is there a way to ensure deep cloning in FB, based on implementing a copy constructor? Or something?
ppf wrote:
Second question: But what in case if we know only pointer particles and type of clone must be recognized in some way ?
This looks intristingly to solve and similar to my previous question (other topic),
going to further searching..
Hi ppf, not sure I understand your question. But VAR B = A, or VAR BYREF B = A, work both very well. (you don't have to know the type of A then, the compiler knows it for you)