mercredi 21 février 2018

How to know if an object was moved

It might be a stupid question but I feel like I am missing some design pattern.

During the destruction of a class I would like to do different operations if it was moved or not. I thought about implementing a simple boolean that is ticked when the class is moved.

Like this:

class A {
    A(const A && a) {
        a.was_moved = true;
    }

~A() {
    do some stuff

    if (!was_moved) {
        clean some more stuff
    }

bool was_moved = false;
};

Is there a "better" way doing this? some cpp feature I could ask if the class was moved or some known design pattern.

Aucun commentaire:

Enregistrer un commentaire