boost smart pointers

This topic is 4844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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.

Share on other sites
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).

Share on other sites
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.

WTF am I doing? I wrote a novel, to see afterwards that cptrnet only asked for help on smart_ptr.[ignore][/edit]

Share on other sites
Quote:
 Original post by stroThen 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.

Share on other sites
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.

Share on other sites
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.

Share on other sites
Another possibility is
boost::shared_ptr&<MyClass&> myPointer;myPointer.reset( new MyClass() );myPointer->doSomething();

thanks

Share on other sites
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...:)

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 18
• 19
• 12
• 14
• 9
• Forum Statistics

• Total Topics
633363
• Total Posts
3011509
• Who's Online (See full list)

There are no registered users currently online

×