08.11.2014 Views

Memory Management - Poco

Memory Management - Poco

Memory Management - Poco

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

#include <br />

#include <br />

using <strong>Poco</strong>::SharedPtr;<br />

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

{<br />

std::string* pString = new std::string("hello, world!");<br />

<strong>Poco</strong>::SharedPtr p1(pString); // rc == 1<br />

<strong>Poco</strong>::SharedPtr p2(p1); // rc == 2<br />

p2 = 0; // rc == 1<br />

// p2 = pString; // BAD BAD BAD: multiple owners -> multiple delete<br />

p2 = p1; // rc == 2<br />

std::string::size_type len = p1->length(); // dereferencing with -><br />

std::cout

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

Saved successfully!

Ooh no, something went wrong!