
colin rafferty wrote:
Peter Dimov wrote:
Colin Rafferty wrote:
Shouldn't the constructor in intrusive_ptr be explicit?
No, the constructor is implicit by design. Do you have a case where the implicit constructor causes problems?
Sure, this is the same problem as for shared_ptr<>.
extern void foo(const intrusive_ptr<Bar>&);
void baz() { Bar* bar = new Bar; foo(bar); // oops! delete bar; }
I thought I was passing a raw pointer into foo(), but I'm actually creating a temporary intrusive_ptr<Bar>, passing that in, and then destroying the temporary and the pointer.
More generally, the problem is that intrusive_ptr<> destroys the object it is passed (on destruction), and having a conversion constructor makes it very easy for a programmer to make a mistake (like above). Can someone please fix this to make the conversion constructor explicit? Thanks. -- Colin