I have created a simple template to make instantiation of shared_ptrs a little prettier. Here is an abridged version of the template: template <class T> class ManagedPointer : public boost::enable_shared_from_this<T> { public: typedef boost::shared_ptr<T> shared_ptr; public: static shared_ptr create () { return (shared_ptr (new T ())); } template <class A1> static shared_ptr create (A1 a1) { return (shared_ptr (new T (a1))); } }; This allows for me to create a class: class TestClass : public ManagedPointer<TestClass> { public: TestClass(); }; and create an instance by: TestClass::shared_ptr test = TestClass::create(); I have noticed in certain cases I get very strange behaviour. Most recently I've seen things hanging in the shared_ptr destructor. Changing the code to: TestClass::shared_ptr test (new TestClass()); does "solve" the problem. Is there something subtle in how the templates and subclassing are interacting that I am not understanding? thanks. e.
Not easily. There are many cases where I've used this template base class without problems, but recently found one case were it was showing this behaviour. Once I made the change mentioned in the previous email, everything /seemed/ to be fixed. I just wanted to make sure I wasn't doing anything illegal by constructing a type in a template base class of that type that would result in the wrong type/incomplete type being constructed (or something similar to that). If the code does not violate any of those sorts of rules, I would assume it was just a coincidence and the problem is likely elsewhere. thanks. e. On Fri, 08 Oct 2004, Peter Dimov wrote:
eric lindvall wrote:
I have noticed in certain cases I get very strange behaviour. Most recently I've seen things hanging in the shared_ptr destructor.
Can you post a complete example that exhibits the problem?
participants (2)
-
eric lindvall
-
Peter Dimov