C++ - Using Pointers as parameters/return for arrays

Ok, so I am trying to wrap my head around C++ by starting out with a simple function library that handles some tasks I know I will need repeatedly throughout my game code. This particular function is meant to fill in an array with values calculated for a clamped sine wave.

BPFLibray.h

	UFUNCTION(BlueprintCallable, Category = "Test")
	int WaveClampedSine(int* amplitude, int* frequency, int* phase);

BPFLibrary.cpp

int WaveClampedSine(int* amplitude, int* frequency, int* phase)
{
	int i;
	int data= (int*)malloc(S*sizeof(int));
	for (i = 0; i <= 99; ++i)
	{
		*data[i] = *amplitude * sin(*frequency * i + *phase);
	};
	return *data;
	
}

I’ve tried implementing this several different ways, and all of them give me the same error:

“Inappropriate ‘*’ on variable of type ‘int’, cannot have an exposed pointer to this type.”

I find it rather difficult to believe that UE4 does not support pointers at all, but it doesn’t seem to matter which data type I try to use, I always get the same error. Am I missing something or doing something wrong here? (And yes, I realize there are probably far more mistakes in my code then I currently realize.)

UFUNCTIONs are meant to be used in Blueprints. There’s no node to get addresses of variables in blueprints. Only UObjects or classes derived from them are references as pointers on the C++ side. Every other data type is passed by reference, including structs.

Your function would be more UE4-esque like this:

UFUNCTION(BlueprintCallable, Category = "Test")
void WaveClampedSine(int amplitude, int frequency, int phase, int num, UPARAM(ref) TArray<int> &Results);

void UYourUObjectClass::WaveClampedSine(int amplitude, int frequency, int phase, int num, TArray<int> &Results)
{
	for (int i = 0; i <= num; ++i)
	{
		Results.Add(amplitude * FMath::Sin(frequency * i + phase));
	}
}

Hi there.

The reason for your error is that unreal engine 4 does not support the int type. The type you are looking for is int32.
For further information take a look at this question:

The next thing is that you should not use pointers to pass the array but use the engines TArray type instead:

And unreal engine has support for pointers as given here:

But a better way than using this smart pointers would be to use the engines implementation of smart pointers as documented here: