Book Image

Learning C++ by creating games with UE4

By : William Sherif
Book Image

Learning C++ by creating games with UE4

By: William Sherif

Overview of this book

Table of Contents (19 chapters)
Learning C++ by Creating Games with UE4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Variables and Memory
Index

UE4's TArray<T>


TArrays are UE4's version of a dynamic array. To understand what a TArray<T> variable is, you first have to know what the <T> option between angle brackets stands for. The <T> option means that the type of data stored in the array is a variable. Do you want an array of int? Then create a TArray<int> variable. A TArray variable of double? Create a TArray<double> variable.

So, in general, wherever a <T> appears, you can plug in a C++ type of your choice. Let's move on and show this with an example.

An example that uses TArray<T>

A TArray<int> variable is just an array of int. A TArray<Player*> variable will be an array of Player* pointers. An array is dynamically resizable, and elements can be added at the end of the array after its creation.

To create a TArray<int> variable, all you have to do is use the normal variable allocation syntax:

TArray<int> array;

Changes to the TArray variable are done using member...