How should I code units in an RTS game?

Use two arrays, before you add one unit to the array that holds all units (TArray) you add one item to the other array (TArray) that will hold the unit’s specific class. Or you could use bidimensional arrays (I never used it).