Copy but do not move

In C ++ 0x, is it legal / expected that some classes can be copied but not moved? I am looking at an implementation of a heterogeneous class that resizes, and I'm not sure I can handle it if some classes need to be copied and some of them are needed.

+5
source share
2 answers

Yes, this is legal for a class that can be copied, but not accessible for moving:

class MyClass {
public:
    /* Copyable... */
    MyClass(const MyClass&);
    MyClass& operator= (const MyClass&);

    /* ... but not movable. */
    MyClass(MyClass&&) = delete;
    MyClass& operator= (MyClass&&) = delete;
};

However, I can’t come up with a good reason why someone would want to do this. Knowing C ++ encoders (like me!), I think you should expect this to happen.

Out of curiosity, which code do you rely on this will break if the class is copied but not moving?

+5

, / - . ? . std::enable_if .

0

All Articles