C++ source code that demos auto_ptr and auto_ptr.release()

(Last Updated On: June 15, 2010)

Project is auto_ptr
using namespace std;

class MyClass {
MyClass() {} // nothing
~MyClass() {} // nothing
void myFunc() { cout<<"hi"< ptr1(new MyClass), ptr2;

ptr2 = ptr1;

MyClass* ptr = ptr2.get();


auto_ptr p1 (new int);

auto_ptr p2 (p1); //transfers ownership from p1 to p2

cout << "p2 points to " << *p2 << "\n"; // (p1 is now null-pointer auto_ptr where next line will cause crash //cout<<"p1 points to "<<*p1< p;

p.reset (new int);
cout << *p << endl; p.reset (new int); cout << "after 2nd reset "<<*p << endl; //this will print junk *p=10; cout << *p << endl; return 0; } Project auto_ptr_release: // auto_ptr::release example #include
using namespace std;

int main () {
auto_ptr auto_pointer (new int);
int * manual_pointer;

cout<<"auto_pointer="<<*auto_pointer< NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Subscribe For Latest Updates

Sign up to best of business news, informed analysis and opinions on what matters to you.
Invalid email address
We promise not to spam you. You can unsubscribe at any time.


Check NEW site on stock forex and ETF analysis and automation

Scroll to Top