Jump to content
  • Advertisement
Sign in to follow this  
cptrnet

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.

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
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.

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

Share this post


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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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...:)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!