Around 3: of course there is. I can think of many examples of objects that can be moved, not copied, or shoudln't, anyway.
One example is the Socket class:
1) you want to provide a default constructor for an "empty" Socket, which so far has not received any IP address or port.
2) you want to give a constructor that receives an IP and port. when building, Socket will try to connect and may throw an exception if the connection does not work
3) the obvious thing is the destructor - it will disable the object and release any resources of the base system that this object may contain
how about move constructor vs copy constructor?
let's say I have a function that creates a socket and returns it. If I call the copy constructor, it means that:
the new copied socket (return value) will try to connect to the same IP and port to which the source was connected. it may not be possible at all.
the source socket will be disconnected and destroyed
it is possible that trying to copy a socket will just create a huge mess. on the contrary, the motion designer solves this mass:
the return value gets all the underlying OS resources, without shutting them down or without destroying them.
the source socket remains empty, and the destructor has nothing to disable or destroy.
it looks like sockets are more likely to be moved than copied.
this may be in the Process class. If I try to return the process by copying, I would try to open the same process again, only to close the original. mess! moving the process around, I do not. I just move the process from function to function.
David Haim
source share