Managed C++

Managed Wrappers and Hidden Interdependencies

Managed Wrappers and Hidden Interdependencies

Let’s say you have the following unmanaged code: #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; }; void f() { 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).