var d = c

does not call the let operator why is it or what i'm doing wrong ?

In this case d is a reference to c (not a new copy) and d.m[3]=10 is in real c.m[3]=10

thank you

Joshy

Code: Select all

`#define _min(x,y) iif((x)<(y),(x),(y))`

type tVector

declare destructor

declare constructor (nDims as integer=0)

declare constructor (x as single,y as single)

declare constructor (x as single,y as single,z as single)

declare constructor (x as single,y as single,z as single,w as single)

declare operator let (byref r as tVector)

declare operator cast as string

as integer n

as single ptr m

end type

destructor tVector

if n then delete [] m

end destructor

constructor tVector(nDims as integer)

print"tVector(" & nDims & ")"

n=nDims: if n then m=new single[n]

end constructor

constructor tVector(x as single,y as single)

n=2:m=new single[n]:m[0]=x:m[1]=y

print "tVector(" & this & ")"

end constructor

constructor tVector(x as single,y as single,z as single)

n=3:m=new single[n]:m[0]=x:m[1]=y:m[2]=z

print "tVector(" & this & ")"

end constructor

constructor tVector(x as single,y as single,z as single,w as single)

n=4:m=new single[n]:m[0]=x:m[1]=y:m[2]=z:m[3]=w

print "tVector(" & this & ")"

end constructor

operator tVector .let (byref r as tVector)

print "let"

n=r.n : if n then m=new single[n] : for i as integer=0 to n-1 : m[i]=r.m[i]:next

end operator

operator tVector . cast as string

var sResult="["

for i as integer = 0 to n-1

sResult &= m[i]:if i<n-1 then sResult &= ","

next

return sResult & "]"

end operator

operator -(l as tVector) as tVector

var res=tVector(l.n)

for i as integer = 0 to l.n-1 : res.m[i]=-l.m[i] : next

return res

end operator

operator -(l as tVector,r as tVector) as tVector

var n=_min(l.n,r.n)

var res=tVector(n)

for i as integer = 0 to n-1

res.m[i]=l.m[i]-r.m[i]

next

return res

end operator

var a = tVector(1,2)

var b = tVector(1,2,3)

var c = tVector(1,2,3,4)

var d = c

var e = a-b

d.m[3]=10

print a,b,c,d,e

print a.n,b.n,c.n,d.n,e.n

sleep