#pragma unmanaged
classStream { ... }; // Conceptual stream class
classStreamWriter{
public: StreamWriter(Stream* pStream) : m_pStream(pStream) {}
~StreamWriter() { /* Use m_pStream in some way */ }
...
private: Stream* m_pStream;
};
voidf()
{
Stream stream;
StreamWriter streamWriter(&stream);
// Use streamWriter
// streamWriter is destroyed
// stream is destroyed
}
Note that StreamWriter’s destructor uses m_pStream (perhaps by flushing the stream). This means that the order of destruction is important — StreamWriter must be destroyed before its underlying Stream is.