5 ms·
Using a moved-from object in C++ doesn't produce any warnings because it isn't an invalid operation. The standard library types make very limited guarantees abo
by plorkyeran 7y ago
Using a moved-from object in C++ doesn't produce any warnings because it isn't an invalid operation. The standard library types make very limited guarantees about the state of moved from objects (generally just that it remains valid to assign to them and that the object's invariants still hold), but even then it's valid to reuse them as long as you first do something that ensures they're in a known state.
- machinecoffee 7y agoI would also argue that even after an object has been moved (out of?), that object should still be a valid object. So that even if somebody makes a call to it, it shouldn't 'blow up' , but do add asserts to indicate you're now talking to an object that is no longer initialized to a useful state. E.g. if moving a class that wraps a file descriptor, then calling write() would do nothing, but a debug build could also assert() that the file descriptor is not valid. That way you get runtime stability if you screw up, but no weird side-effects.