This idea works well with std::vector, allowing the initialization of vectors as member variables within the class’ initializer list. Obviously that’s preferable to first creating the object and the vector, then in the constructor giving it a size. Why write
int a;
a = 5;
When you could just use
int a = 5;
Same deal here - we should be able to do something with most dynamic arrays, right?
struct FObjectCollection
{
FObjectCollection(int a_numObjects)
: m_IDs(std::vector<int>(a_numObjects))
{
}
std::vector<int> m_IDs;
};
This works. But TArray doesn’t support this.
struct FObjectCollection
{
FObjectCollection(int32 a_numObjects)
: m_IDs(TArray<int32>(a_numObjects))
{
}
TArray<int32> m_IDs;
};
It would be fantastic if it could!