Confuse at Function return

Hi i’m new in community . I just start learning C++ . Now i get a bit confuse at Function. In Pytthon , I can return any data type like list tuple or other data type that python support in Custom Function . But i can’t do it in C++.
can anyone help me with this ? i want to make function export a list as result.

1 Like

You can do this. It’s not difficult but is it Unreal C++ or regular C++?

for unreal, you can use TArray which would return an array of the specified type. You can read more about this here: TArray: Arrays in Unreal Engine | Unreal Engine Documentation

For plain C++, there’s a series of libraries called the STL which are available on most platforms.
the easiest of these for a collection is the std::vector. See here for documentation. vector - C++ Reference (cplusplus.com)

In both cases, declaring a function is similar. I will use the vector as an example

#include <vector>

std::vector<int> GetVector() {
  std::vector myVector;
  myVector.push(1);
  myVector.push(2);
  myVector.push(3);
  return myVector
}

For the TArray in Unreal, just change the std::vector with TArray and instead of push, use .Add

Privacy & Terms