Tools.h++ Class Reference

Table Of Contents
well-defined equality semantics (T::operator==(const T&)).
Persistence
Isomorphic
Example
In this example, a doubly-linked list of pointers to the user type Dog is exercised. Contrast this
approach with the example given under RWTValDlist<T>.
#include <rw/tpdlist.h>
#include <rw/rstream.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; }
friend ostream& operator<<(ostream& str, const Dog& dog){
str << dog.name;
return str;}
};