// ------------------------------------------------------------------------ // Ordered base class -- An abstract class // A. Fischer June 8, 1998 file: ordered.hpp // #pragma once #include #include using namespace std; // How should an ordered abstract class be defined? // // The primary interface defines an ordering relation between // an element and a KeyType. // // The alternative interface defines an abstract ordering relation // on elements of type "Ordered". This appears to be more general, // but it requires some means of obtaining the data to be used // in defining the comparison operators; hence the key() function. // // To allow both interfaces to be explored, the symbol below // selects which interface is to be used. #define PRIMARY_INTERFACE // ------------------------------------------------------------------------ template class Ordered { public: virtual ~Ordered(){} // Promises #ifdef PRIMARY_INTERFACE virtual bool operator < (const KeyType&) const =0; virtual bool operator == (const KeyType&) const =0; #else // Alternative interface virtual KeyType key() const =0; virtual bool operator < (const Ordered&) const =0; virtual bool operator == (const Ordered&) const =0; #endif };