Issue with dereferencing and = operator.
I was working with a TArray of pointers and I had some trouble. The TArray is of size 1000 and my goal is to copy the first 500 to the second 500. Originally I did it like this
Here CreatureList is a TArray, but since an element of CreatureList is a pointer, its passing that pointer and when the function Mutate is called, both the creature at index i and index i - 500 reflect the changes of the Mutate function.
Note: The elements of CreatureList must be pointers because I need them to be polymorphic and from what I understand polymorphism only works with pointers in c++ (Correct me if I'm wrong about that)
I discovered a solution outside of unreal engine which worked perfectly fine.
But when I use this syntax in unreal engine I get an error saying "UCreature &UCreature::operator=(const UCreature &) declared at line 27 of Creature.h is inaccessible" In my header file, line 27 is
Does anybody have any insight into why I'm not allowed to use this operator here? If there are any alternatives or workarounds, that would be great as well. I'm making an evolution simulator, and if every creature is mutating instead of a specific one in the population, then that would cause problems. Thanks!
asked Mar 06 '19 at 01:06 AM in C++ Programming
Try replacing line:2 with
Instantiating an UObject has too many things happening under the hood. That's why they overload the operator "=" to prevent users from copying by themselves.
Follow this question
Once you sign in you will be able to subscribe for any updates here