Operator_Convert and Arrays

I’m creating a wrapper for the Boolean data type called pBoolean.

I’ve implemented Operator_Convert methods in the pBoolean class to allow for general conversion between the two types.

However, I can’t seem to find as elegant a way to express the conversion between Boolean and pBoolean arrays.

Right now, this compiles:

[code]dim b as Boolean
dim p as pBoolean

p = false
b = true
p = b
b = p[/code]

But, this does not compile:

[code]dim b() as Boolean

dim p(2) as pboolean

p(0) = false
p(1) = true
p(2) = false

b = p[/code]

Can someone please explain to me how I can extend the implicit conversion to the case of arrays?

Implement a pair of Operator_Subscript methods for the class, e.g.

Function Operator_SubScript(ArrayIndex As Integer) As pBoolean
Sub Operator_SubScript(ArrayIndex As Integer, Assigns NewBool As pBoolean)

Also handy: Operator_Redim

See also this post on the old forum for example code using Operator_Subscript: Xojo Programming Forum

However, I don’t think you can do what Michael would like to do, the same way you can’t do:

dim a1() as UInt64
dim a2() as Int64
a1 = a2

The variable doesn’t really hold values, it holds a reference to an area of memory where the values live. When you try to assign a2 to a1, you are not copying the array, you are assigning the same reference to another variable, and the compiler expects there to be the same data type there.

Boolean and pBoolean are different types, so the best you can do is create a shared class method like “CreateFrom ( boolArr() As Boolean) As pBoolean()”. You’d call it as:

dim b() As Boolean
dim p() As Boolean = pBoolean.CreateFrom( b )

[quote=16432:@Kem Tekinay]However, I don’t think you can do what Michael would like to do, the same way you can’t do:

dim a1() as UInt64
dim a2() as Int64
a1 = a2

The variable doesn’t really hold values, it holds a reference to an area of memory where the values live. When you try to assign a2 to a1, you are not copying the array, you are assigning the same reference to another variable, and the compiler expects there to be the same data type there.

Boolean and pBoolean are different types, so the best you can do is create a shared class method like “CreateFrom ( boolArr() As Boolean) As pBoolean()”. You’d call it as:

dim b() As Boolean dim p() As Boolean = pBoolean.CreateFrom( b ) [/quote]

Ahhhh, dang. I figured as much, but was hoping that the language had a more implicit mechanism and that I just missed it somehow. Thanks though!