Header File Changes
Starting with the header files, add the following macros:
*RW_DECLARE_VIRTUAL_STREAM_FNS(classname), which declares the streamContents() member function needed to serialize a class out to a virtual stream. Place this within the class declaration.
*RW_DECLARE_STREAMABLE_POINTER(classname), which declares the global input and output operators needed for an object pointer to be written out and later restored. Because this macro declares global operators, you must place it outside the class declaration. The safest location for this macro declaration is immediately following the declaration of the class to which it applies.
*RW_DECLARE_STREAMABLE_AS_SELF(classname), which declares the factory for your class and declares its registrar. This allows objects to be created on the fly from the stream.
*RW_DECLARE_STREAMABLE_AS_BASE(classname), which declares the factory for your class and declares its registrar for serialization through base class pointers.
Here is the revised code for the header files:
 
// from real_property.h
 
class real_property
{
RW_DECLARE_VIRTUAL_STREAM_FNS(real_property)
 
public:
 
real_property() {}
 
real_property(const RWCString& address,
const RWCString& size)
: address_(address), size_(size)
{}
 
virtual ~real_property() {}
 
bool operator== (const real_property& prop) const {
return address_ == prop.address_;
}
 
private:
RWCString address_;
RWCString size_;
};
 
RW_DECLARE_STREAMABLE_POINTER(real_property)
RW_DECLARE_STREAMABLE_AS_SELF(real_property)
 
// from residential.h
 
class residential : public real_property
{
RW_DECLARE_VIRTUAL_STREAM_FNS(residential)
 
public:
 
residential()
{}
residential(const RWCString& address, const RWCString& size,
long footage)
: real_property(address, size),
footage_(footage)
{}
bool operator== (const residential& prop) const {
return real_property::operator==(prop);
}
 
private:
long footage_; // Square footage of the house
};
 
RW_DECLARE_STREAMABLE_AS_SELF(residential)
RW_DECLARE_STREAMABLE_AS_BASE(residential, real_property)
RW_DECLARE_STREAMABLE_POINTER(residential)
 
 
// from rural_land.h
 
class rural_land : public real_property
{
RW_DECLARE_VIRTUAL_STREAM_FNS(rural_land)
 
public:
 
rural_land()
{}
rural_land(const RWCString& address, const RWCString& size,
double irrigation = 0.0)
: real_property(address, size), irrigation_(irrigation)
{}
bool operator== (const rural_land& prop) const {
return real_property::operator==(prop);
}
 
private:
double irrigation_; // Irrigation acres for the property
};
 
RW_DECLARE_STREAMABLE_AS_SELF(rural_land)
RW_DECLARE_STREAMABLE_AS_BASE(rural_land, real_property)
RW_DECLARE_STREAMABLE_POINTER(rural_land)