home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
SAMPLES
/
ICLCC
/
ANIMAL.H
next >
Wrap
C/C++ Source or Header
|
1993-05-07
|
3KB
|
66 lines
/******************************************************************************/
/* */
/* COPYRIGHT: */
/* ---------- */
/* Copyright (C) International Business Machines Corp., 1991,1992. */
/* */
/* DISCLAIMER OF WARRANTIES: */
/* ------------------------- */
/* The following [enclosed] code is sample code created by IBM */
/* Corporation. This sample code is not part of any standard IBM product */
/* and is provided to you solely for the purpose of assisting you in the */
/* development of your applications. The code is provided "AS IS", */
/* without warranty of any kind. IBM shall not be liable for any damages */
/* arising out of your use of the sample code, even if they have been */
/* advised of the possibility of such damages. */
/* */
/******************************************************************************/
// animal.h - Class Animal for use with the example animals.C
// For definition of Boolean:
#include <iglobals.h>
// Class ToyString:
#include "toystrng.h"
class Animal {
ToyString nm;
ToyString attr;
public:
Animal(char* n, char* a) : nm(n), attr(a) {}
// For copy constructor we use the compiler generated default.
// For assignment we use the compiler generated default.
Boolean operator==(Animal const& p) const {
return ((nm == p.nm) && (attr == p.attr));
}
ToyString const& name() const {
return nm;
}
ToyString const& attribute() const {
return attr;
}
friend ostream& operator<<(ostream& os, Animal const& p) {
return os << "The " << p.name().text()
<< " is " << p.attribute().text() << ".\n";
}
};
// Key access:
inline ToyString 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 char*.
inline unsigned long hash(ToyString const& ts, unsigned long n) {
return hash(ts.text(), n);
}