I am trying to create a TArray
of my own data-type APlaying_Card
. I get an error Cannot access private member in class APlaying_Card
.
In the Unreal documentation for TArray it states:
A dynamically sized array of typed elements. Makes the assumption that your elements are relocate-able;
i.e. that they can be transparently moved to new memory without a copy constructor.
The main implication is that pointers to elements in the TArray may be invalidated by adding or removing other
elements to the array. Removal of elements is O(N) and invalidates the indices of subsequent elements.
Caution: as noted below some methods are not safe for element types that require constructors.
There are two things I don't fully understand. First is the 'relocate-able' part, what does it mean to ensure it can be moved without a copy constructor and how is this done? Secondly, regarding the final statement in their remarks, How can I safely make an array of my own objects, if they do require a constructor?
As always thank you for your help.
Dealer
that is an actor, and this actor can declare the same array without the error. Progress is made little by little :DUObject
s must be allocated by ultimately callingNewObject
, aTArray
instead calls the standardnew
ornew[]
operator. The solution is to use an array of pointers insteadTArray<APlaying_Card*>
soAPlaying_Card
itself won't ever need to be reallocated.UObject
s are also garbage collected so you won't ever need to worry about deleting them, althoughAActor
s are an exception since they're referenced by the owning world. If this array is intended to be owning you'll need to remember to call DestroyActor when popping an element.