Third Change
After adding these macros, use the new pointer-based operators to write a real_property pointer to an object stream, and then read it back. Note that the serialization factory has constructed a new real_property instance that is now owned by the module calling the input operator. The following is an example of writing a real_property pointer into a file and then reading it back again.
 
// examples\serial\simple\real_estate2.cpp
 
real_property real1("1980 Main St. Corvallis, Oregon","50x100");
real_property* real2 = 0;
{
ofstream fout(“real_estate2.dat”);
RWpostream postr(fout);
 
RWObjectOutputStream out = RWCompactObjectOutputStreamImp::
make(RWDataToVirtualOutputStreamImp::
make(postr)); // 1
out << &real1; // 2
}
 
ifstream fin("real_estate2.dat");
RWpistream pistr(fin); // 3
 
RWObjectInputStream in = RWCompactObjectInputStreamImp::
make(RWDataFromVirtualInputStreamImp::
make(pistr)); // 4
 
in >> real2; // 5
//1 Create a data stream using the standard file stream just opened and then create a compact object output stream from the data stream. The second parameter indicates the kind of object that will serve as the root element.
//2 Stream out the real_property object by reference.
//3 Open the file for input.
//4 Create a data stream and then create a compact object input stream from the data stream.
//5 Read the data back in to a fresh real_property object. The input stream allocates and constructs a new real_property object as part of the extraction process. Any address held by real2 prior to that operation is lost.