TArray* Operator missing "="

Hello. Suppose there is a method “Assign”, which takes a link to the array TArray◄FVector►:

void Assign(TArray◄FVector►& Array){}

Inside method, I pass a link to the pointer:

PointerToArray = &Array;

where PointerToArray is TArray◄FVector►* PointerToArray. And I want to assign a value to an array through it, but this is not so easy. In two versions:

  1. Array[0] = FVector::FVector(1, 1, 1);
  2. PointerToArray[0] = FVector::FVector(1, 1, 1);

The first case works, and the second says “Operator missing “=””. How can I change the value in an array through a pointer?

It looks like you might need to de-referene the PointerToArray first.
Basically, the [0] is grabbing [0] from the pointer, not the actual array.

You should use:
*PointerToArray[0] = FVector::FVector(1, 1, 1);

Although, keep in mind that [0] might be invalid and so de-referencing without checking its validity could cause a crash.

No, unfortunately, in this case, the compiler gives an error. But you can write this:

PointerToArray->operator = FVector::FVector(1, 1, 1);

it works (array bracket operator. Returns reference to element at give index) :slight_smile:

Ah my bad. It should put the thing you are de-referencing in brackets:

(*PointerToArray)[0] = FVector(1, 1, 1);

Why can’t you just use the array reference anyway:

Array[0] = FVector(1, 1, 1);

What are you trying to do here?

Thanks, it works :slight_smile:

I pass the link to the array to a separate thread, which then in the Run function in the critical section updates the data through the pointer.