Syntax error when calling UStruct functions.

  1. Not directly related to your problem, but careful with “TArray<FMyStruct> SArr;”. The type you pass as template parameter must conform to some specification (see documentation about TArray) such as " Makes the assumption that your elements are relocate-able; i.e. that they can be transparently moved to new memory without a copy constructor.". Also if later you add attributes to this class, this may create performance issues or even runtime issues depending on their type. If in doubt, use pointers instead such as “TArray<FMyStruct*> SArr;”
  2. the member function is named GetValueInSlot() but you are calling CurrentStruct.GetValInSlot()
  3. the following code compiles fine under VS2017. It is syntaxically correct but as mentioned in 1. it may not be optimal.


USTRUCT()
struct FMyStruct
{
	GENERATED_USTRUCT_BODY()

		UPROPERTY()
		TArray<int32> IntArr;

public:
	FMyStruct() {}
	int32 GetValueInSlot(int32 Index) const
	{
		return IntArr[Index];
	}

	FMyStruct(int32 ArrSize)
	{
		IntArr.Init(0, ArrSize);
	}
};


class AnotherClass {
	TArray<FMyStruct> SArr;
	int32 Index;
	FMyStruct CurrentStruct;
public:
	AnotherClass();
	int32 GetStructArrVal(int32 InIndex);
};


AnotherClass::AnotherClass()
{
	SArr.Add(FMyStruct(1));
	SArr.Add(FMyStruct(2));
	SArr.Add(FMyStruct(3));

	CurrentStruct = SArr[0];
}

int32 AnotherClass::GetStructArrVal(int32 InIndex)
{
	return CurrentStruct.GetValueInSlot(InIndex);
}