stream / container / shared_ptr
Hello, Anyone has an idea why this code crashes: // snippet on #include <list> #include <string> #include <iostream> #include <boost/shared_ptr.hpp> struct null_deleter { void operator()(void const *) const {} }; int main() { std::list<boost::shared_ptr<std::ostream> > l; boost::shared_ptr<std::ostream> p(&std::cout, null_deleter()); *p << "on the shared pointer" << std::endl; l.push_back(p); std::list<boost::shared_ptr<std::ostream> >::iterator it = l.begin(); std::cout << "before loop" << std::endl; while (it++ != l.end()) { boost::shared_ptr<std::ostream> p2 = *it; *p2 << "test" << std::endl; // crash here } return 0; } // snippet off // output on on the shared pointer before loop segmentation fault // output off It crashes on: std::ostream::sentry::sentry () from /usr/lib/libstdc++.so.6 Thanks.
participants (2)
-
JD
-
Peter Dimov