Declaring the Basic Classes
The code below shows the base class real_property and its two derived classes residential and rural_land. It is based on the example code in the \examples\xmlstreams\real_estate directory.
Here is the declaration for the base class real_property:
 
class real_property
{
public:
real_property() {} // 1
real_property(const RWCString& address,
const RWCString& size)
: address_(address), size_(size)
{}
virtual ~real_property() {} // 2
 
 
bool operator== (const real_property& prop) const {
return address_ == prop.address_;
}
 
private:
RWCString address_;
RWCString size_;
};
//1 This is the explicit default constructor required in serializable classes.
//2 At least one virtual function is needed, because the by-reference streaming facility relies on RTTI, and that requires a v-table.
Here are the declarations for the two derived classes residential and rural_land:
 
class residential : public real_property
{
public:
residential() // 1
{}
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
};
 
 
class rural_land : public real_property
{
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
};
//1 The derived classes also require an explicit default constructor.
Note that the derived classes residential and rural_land inherit a virtual function from the base class and therefore fulfill the requirement for serializable classes.