Sign in to follow this  
olberg

boost::shared_ptr and stack overflow

Recommended Posts

I converted my program to use boost::shared_ptr instead of normal pointers. I have class with std::vector with shared pointers in it and when I clear the vector I got crash with stack overflow and access violation in the vector. This is my first time using shared pointers in a complex program so it's probably caused by my bad design. I have something like this:
class MyClass
{
    // something
    vector<shared_ptr<AnotherClass>> my_vector;
};

class SecondClass
{
    // something else
    vector<shared_ptr<AnotherClass>> another_vector; // may have same elements with my_vector
};
Is this OK? Or how should I use shared pointers? And if anybody has a good guess what's causing the stack overflow, let me know.

Share this post


Link to post
Share on other sites
A stack overflow frequently indicates infinite recursion. Look at the call stack. Does the AnotherClass destructor affect the vectors in MyClass or SecondClass?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this