It seems that the use of auto_ptr<> is discouraged in many places in
favor of boost::shared_p tr<> (or tr1::shared_ptr <>). But consider a
PIMPL idiom, where there is a strict 1-1 relationship between interface
objects and implementation object, and the implementation object lasts
for the lifetime of the interface object.
i.e.
// header file
class WidgetImpl;
class Widget {
private:
WidgetImpl* const pImpl;
public:
Widget();
~Widget();
// yada yada yada
};
// source file
class WidgetInterface {
private:
friend class WidgetInterface ;
WidgetImpl() { }
~WidgetImpl() { }
// yada yada yada
};
Widget::Widget( ) : pImpl(new WidgetImpl)
{
}
Widget::~Widget ()
{
delete pImpl;
}
In this case, is there any thing wrong with making Widget::pImpl an
auto_ptr<Widget Impl>? It seems to me that this would be a bit safer as
well.
favor of boost::shared_p tr<> (or tr1::shared_ptr <>). But consider a
PIMPL idiom, where there is a strict 1-1 relationship between interface
objects and implementation object, and the implementation object lasts
for the lifetime of the interface object.
i.e.
// header file
class WidgetImpl;
class Widget {
private:
WidgetImpl* const pImpl;
public:
Widget();
~Widget();
// yada yada yada
};
// source file
class WidgetInterface {
private:
friend class WidgetInterface ;
WidgetImpl() { }
~WidgetImpl() { }
// yada yada yada
};
Widget::Widget( ) : pImpl(new WidgetImpl)
{
}
Widget::~Widget ()
{
delete pImpl;
}
In this case, is there any thing wrong with making Widget::pImpl an
auto_ptr<Widget Impl>? It seems to me that this would be a bit safer as
well.
Comment