Is it possible not to destroy obj while the destructor is running?

If I override the destructor of my class, can I check if this instance should be killed or sent to the pool? I want to simplify the reuse of obj, the user only needs to free it (or leave it to the compiler), and the destructor will check if it can be reused.

ReusableClass::~ReusableClass() {
  if (x == 1) {
    // abort destructor, send to pool
  }
}
+4
source share
2 answers

As soon as the object's destructor is started, the object is considered dead: 12.4 [class.dtor] paragraph 14:

As soon as the destructor is called for the object, the object no longer exists; ...

+4
source

Of course not - you would also not have a reference to the object - how could you recycle the object?

, . , , , (, Java) ( ), .

0

Source: https://habr.com/ru/post/1528839/


All Articles