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.
int WaveClampedSine(int* amplitude, int* frequency, int* phase)
int data= (int*)malloc(S*sizeof(int));
for (i = 0; i <= 99; ++i)
*data[i] = *amplitude * sin(*frequency * i + *phase);
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));