home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
IOC
/
ANIMALS
/
ANIMAL.H
next >
Wrap
Text File
|
1995-03-15
|
2KB
|
61 lines
/*************************************************************************
IBM C/C++ Tools Version 3.00 - Collection Class Library
(C) Copyright IBM Corporation 1992 ,1995, Licensed Program-Property of
IBM. All Rights Reserved. US Government Users Restricted Rights - Use,
duplication or disclosure restricted by GSA ADP Schedule Contract with
IBM Corp.
*************************************************************************/
// animal.h - Class Animal for use with the example animals.C
#include <iglobals.h> // For definition of Boolean:
#if defined (_SUN)
#include <istring.h> // Class IString:
#else
#include <istring.hpp> // Class IString:
#endif
#include <iostream.h>
class Animal {
IString nm;
IString attr;
public:
Animal(IString n, IString a) : nm(n), attr(a) {}
// For copy constructor we use the compiler generated default.
// For assignment we use the compiler generated default.
IBoolean operator==(Animal const& p) const {
return ((nm == p.name()) && (attr == p.attribute()));
}
IString const& name() const {
return nm;
}
IString const& attribute() const {
return attr;
}
friend ostream& operator<<(ostream& os, Animal const& p) {
return os << "The " << p.name() << " is " << p.attribute()
<< "." << endl;
}
};
// Key access:
inline IString const& key(Animal const& p) {
return p.name();
}
// We need a hash function for the key type as well.
// Let's just use the default provided for IString.
inline unsigned long hash(Animal const& animal, unsigned long n) {
return hash(animal.name(), n);
}