Affine structures on a class of virtually nilpotent groups