unique_ptr reset is giving error where auto_ptr reset is working

Viewed 64

To comply with new c++ standard I am changing my auto_ptr to unique_ptr however that is causing following issue

class A {
static std::unique_ptr<A> ptr; //changed from auto_ptr to unique_ptr
...
}
void A::EndU(...)
{
    ptr.reset();
}
A::~A() {
    Reset(this);
}
void A::Reset(A* inst) {
    fassert(A::ptr.get() == inst, ...); // Assertion Failure
    A::ptr.release();
}

ptr.reset triggers ~A which calls Reset, but since now its a unique_ptr the assertion fails as calling ptr.get() inside a ptr.reset calls results in returning 0 or null. what is the proper way to deal with this issue? should I use a different pointer type if I have to use ptr.get() inside ptr.reset or doing this is a bad practice?

0 Answers
Related