The formation of barium and CH stars and related objects