Use pure virtual functions.
Use a temporary variable row_id instead of row_ids[i].