#include #include using namespace std; // defines Pair as a template with two // template parameters template < class Key, class Data > class Pair { public: // default constructor Pair( ); // destructor ~Pair( ); // copy constructor Pair( const Pair& pair); // equality operator bool operator== (const Pair& rhs) const; private: Key m_key; Data m_data; }; // Pair's equality operator template bool Pair::operator== (const Pair& rhs) const { return m_key == rhs.m_key && m_data == rhs.m_data; } int main ( ) { string bob = "bob"; string mary = "mary"; // use pair to associate a string and its length Pair< int, string > boy (bob.length(), bob); Pair< int, string > girl (mary.length(), mary); // make a new pair using copy constructor Pair dad = boy; // check for equality if (bob == girl) cout << "They match\n"; // use Pair for names and Employee object Employee john, mark; Pair< string, Employee> boss ("john", john); Pair< string, Employee> worker( "mark", mark); if (boss == worker) cout << "A real small company\n"; return 0; }