fbpx

A C++ smart pointer including auto_ptr and shared_ptr and difference from Boost

(Last Updated On: May 17, 2010)

C++ smart pointers including auto_ptr and shared_ptr

Note this is not complete!!

Smart pointers are used to prevent dangling pointers.
This is a demo of an auto_ptr:
#include
using namespace std;

class MyClass {
public:
MyClass() {} // nothing
~MyClass() {} // nothing
void myFunc() {} // nothing
};

int main() {
auto_ptr ptr1(new MyClass), ptr2;

ptr2 = ptr1;
ptr2->myFunc();

MyClass* ptr = ptr2.get();

ptr->myFunc();

return 0;
}
}
Auto_ptr has ownership but when you assign to another auto pointer, the assign auto pointer will lose ownership. The right hand side can also get modified.
Need to complete both types including shared_ptr within Boost. Need to know pros and cons of each.

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!
Don't miss out!
Get my TRADE LIKE A BOSS 2 PDF Books

You will received instantly the download links.

Invalid email address
Give it a try. You can unsubscribe at any time.

NOTE!

Check NEW site on stock forex and ETF analysis and automation

Scroll to Top