jeudi 19 août 2021

Effect of std::move

struct Base
{
    Base(int a_) : a(a_)
    {
    }
    int a;
};
class Derived: public Base
{
public:
    Derived(int i): Base(i)
    {

    }
    Derived(Derived const&& rhs)
        : Base(std::move(rhs))
    {
    }
};

int main()
{
    Derived d1(2);
    Derived d2 = std::move(d1);
}

what effect does it bring in to main if reimplement

Derived(Derived const&& rhs)

as

Derived(Derived const&& rhs): Base(rhs)
{
}

Does d1.a change its value? I know that it does not, and that bothers me. I expected an undefined value, but d1.a is still equal to 2, though I moved it, and it should been "died"..

Aucun commentaire:

Enregistrer un commentaire