What's wrong with this code?

You showed us the code, ok. You didn’t give us the question/task asked to you. We can only be working on guesses here. Quite unfair imho.

As we don’t know the premises, but only the code, the only things that would produce a bad response to that code are:

  • lack of pointer checks: which includes GetWorld() because we don’t know the context where DoArrayWork() will be called and a valid World might not exist;
  • you assume the array inside PrintArray has valid elements and are not checking if the element there is valid, so *Actor->GetName() would fail. Anyone which would use PrintArray() might not know that the array elements were inserted using SpawnActor() in first place, meaning you are using an assumption, which might be invalid.
  • it would be a better code if you receive the World pointer as parameter to know where to create actors at;
  • array passed by value, surely is a performance issue there, it could be a reference or a const value;

Those from all everyone posted here up to now.

PS: I saw that after this post you fixed the question