Tools.h++ Class Reference

Table Of Contents
Parameter T represents the type of object to be inserted into the list, either a class or fundamental type.
The class T must have:
A default constructor;
well-defined copy semantics (T::T(const T&) or equivalent);
well-defined assignment semantics (T::operator=(const T&) or equivalent);
well-defined equality semantics (T::operator==(const T&)).
Persistence
Isomorphic
Example
In this example, a doubly-linked list of user type Dog is exercised.
#include <rw/tvdlist.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;
}