Comparing 2 objects

BlitzMax Forums/BlitzMax Programming/Comparing 2 objects

This won't work, as you've declared the parameters of your function as Ints, you will get an "Unable to convert from ... to 'Int'" error.

You could use this instead:
Type test1
End Type

Type test2
End Type

testa:test1 = New test1
testb:test2 = New test2
testc:test1 = testa
testd:test1 = New test1

Print CompareObjects(testa, testc)

Function CompareObjects(o1:Object, o2:Object)
	Return (o1 = o2)
End Function


Note that this function only returns "1" when both o1 and o2 point to the same object (array, string, custom type instance, ...).

I can however accept anything (ints, strings, arrays, ...).
It prints "0" if both variables (o1 and o2) don't point to the same object.
In this example, testa and testc point to the same object and therefore the function returns "1".
If you would supply testa and testd to the function, it returns "0", as testa isn't pointing to the same test1-instance as testd (the function just compares the memory-address of both objects, which isn't the same for testa and testd).