Overloading the [....] brackets

Hello :slight_smile:

I wanted to know, if I am able to overload this brackets here: [1,2,3,5,6]?

like for my own-array-stuff:

var a :  TArray<byte> := [0,2,4,56,1000];

Would be nice to know :slight_smile:

–Shpend

overload?

yes, overload, I want to make this syntax also possible for own-created-classes, like the one I have.

Isn’t it an operator-overloading?

operators work on operands, unary or binary. which operator is used is determined by the type one the operand(s). how would the compiler determine to use “your” version of [] instead of creating an array, in this instance?

Yes, this is not overloading in that sense.

Ok, this was not well formulated by me, I wanted just to know, if I can do:

var a :  TArray<byte> := [0,2,4,56,1000];

instead of:

var a :  TArray<byte> := new TArray<byte>(0,2,4,56,1000);

thats all

For that, I explictely wrote var a: TArray that he can see, aha, he wants the for his type and not an array, without the bracktes, yes otherwise, he would interpret it as an array of byte, at least in my head…

Make an implicit conversion from array of T to your array type?

1 Like

Ok, yeah, I forgot that this is possible, thank you.

1 Like