Why move semantics requires rvalue reference?

Viewed 49

C++11 introduced a new value category rvalue reference which would allow to apply move semantics. To me, it is not quite clear why move semantics required a new value category.

Couldn't I just pass a pointer to an object to be moved? Just as an example:

class MyIntArray {
private:
    int* data;
    size_t size;

public:
    // I'll only specify a move constructor for brevity
    MyIntArray(MyIntArray* other) : size(other->size) {
        data = other->data;
        other->data = NULL;
        other->size = 0;
    }
}

Why move semantics required a special value category?

0 Answers
Related