next up previous
Next: Using clone() Up: The Strategy Pattern Previous: Improved Implementation

clone()

The clone() function should create a copy of an object on the heap.
class DistanceBase
{
public:
...
    virtual DistanceBase* clone() const = 0;
};
 
class L1Distance : public DistanceBase
{
...
    virtual DistanceBase* clone() const
    { return new L1Distance(*this); }
};



Tim Cootes
2/24/1998