boost smart pointers

Started by
8 comments, last by garyfletcher 18 years, 8 months ago
I have downloaded the exe and extracted the contents of the boost library. I'm going through there docs and I cannot understand it at all. Do I need to install it somehow? What do I need to do so I can start using it? And if anyone knows where some tutorials are please let me know. I am using vs2003.
If you insist on saying "DUH", try to make a post that makes a little more sense
Advertisement
To get boost's smart pointers working you just have to add the directory with the header files to VC's list of include directories. Go to Tools->Options->Projects->VC++ Directories. Select Show Directories for Include Files. Then add the directory containing the smart_ptr.hpp file (the folder should be called boost and is whereever you extracted the contents of the archive you downloaded).
First, you need to add the boost directory to your include path, so you can later
#include <boost/stuff.hpp>


The Boost libraries are mostly include-only, but some (regex etc.) need to be compiled with bjam.

Other than that, the boost documentation usually contains a few tutorials on each subject.

Interesting libraries include


and many, many more.

[edit]WTF am I doing? I wrote a novel, to see afterwards that cptrnet only asked for help on smart_ptr.[ignore][/edit]
Quote:Original post by stro
Then add the directory containing the smart_ptr.hpp file (the folder should be called boost and is whereever you extracted the contents of the archive you downloaded).


I think it's better to add the the top-level boost directory to the include path, so that it's clear when you include <boost/stuff.hpp> and to avoid header name clashes.
Yup, my bad.
Its giving me an error saying it can't find the file or directory. I have included the boost folder in my project build directory.

EDIT : Alright i got it to compile, but now hoe do I use it. I'm trying to look through google but all I find is a bunch of code I don't under stand. The main thing Im tring to do is use it with classes that I have that error out when I close the program, probably cause of memory allocation.
If you insist on saying "DUH", try to make a post that makes a little more sense
Try something like:
boost::shared_ptr<MyClass> myPointer(new MyClass);myPointer->doSomething();

The MyClass will automatically be released as soon as all copies of the pointer have gone out of scope.
Another possibility is
boost::shared_ptr&<MyClass&> myPointer;myPointer.reset( new MyClass() );myPointer->doSomething();

thanks
If you insist on saying "DUH", try to make a post that makes a little more sense
There can be issues with cyclic code when using boost::smart_ptr, so you might also want to look at boost::weak_ptr as well (the 2 are pretty closely linked).

Just a thought...:)
Gary.Goodbye, and thanks for all the fish.

This topic is closed to new replies.

Advertisement