Tools.h++ Manual

104011 Tandem Computers Incorporated 22-21
22
RWTPtrDlist<T>
Synopsis
#include <rw/tpdlist.h>
RWTPtrDlist<T> list;
Description This class maintains a collection of pointers to type
T
, implemented as a doubly
linked list. This is a pointer based list: pointers to objects are copied in and out
of the links that make up the list.
Parameter
T
represents the type of object to be inserted into the list, either a
class or built in type. The class
T
must have:
well-defined equality semantics
(T::operator==(const T&)).
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>
.
Code Example 22-1 (1 of 2)
#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) {