08.11.2014 Views

Memory Management - Poco

Memory Management - Poco

Memory Management - Poco

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

#include "<strong>Poco</strong>/AutoPtr.h"<br />

#include "<strong>Poco</strong>/RefCountedObject.h"<br />

class A: public <strong>Poco</strong>::RefCountedObject {};<br />

class B: public A {};<br />

class C: public <strong>Poco</strong>::RefCountedObject {};<br />

int main(int argc, char** argv)<br />

{<br />

<strong>Poco</strong>::AutoPtr pA;<br />

<strong>Poco</strong>::AutoPtr pB(new B);<br />

pA = pB;<br />

pA = new B;<br />

// okay, pB is a subclass of pA<br />

// pB = pA; // will not compile<br />

pB = pA.cast();<br />

// okay<br />

<strong>Poco</strong>::AutoPtr pC(new C);<br />

pA = pC.cast();<br />

// pA is null<br />

}<br />

return 0;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!