class DistanceBase { public: ... virtual DistanceBase* clone() const = 0; }; class L1Distance : public DistanceBase { ... virtual DistanceBase* clone() const { return new L1Distance(*this); } };