Tools.h++ Class Reference

Table Of Contents
Persistence
Isomorphic
Example
In this example, a pointer-based doubly-linked list of user type Dog is exercised.
//
// tpdlist.cpp
//
#include <rw/tpdlist.h>
#include <iostream.h>
#include <string.h>
class Dog {
char* name;
public:
Dog( const char* c) {
name = new char[strlen(c)+1];
strcpy(name, c); }
~Dog() { delete name; }
// Define a copy constructor:
Dog(const Dog& dog) {
name = new char[strlen(dog.name)+1];
strcpy(name, dog.name); }
// Define an assignment operator:
void operator=(const Dog& dog) {
if (this!=&dog) {
delete name;
name = new char[strlen(dog.name)+1];
strcpy(name, dog.name);
}
}
// Define an equality test operator:
int operator==(const Dog& dog) const {
return strcmp(name, dog.name)==0; }
// Order alphabetically by name:
int operator<(const Dog& dog) const {
return strcmp(name, dog.name)<0; }