What do you mean how can a person invest?
They buy an asset that is subject to Capital Gains Tax eg land, buildings or shares.
Then when they make a capital gain they use the losses to reduce the gain.
The asset in which the gain is made does not have to be the same as the asset on which the loss was made. So a gain on shares can be reduced by a loss on property.