3 ms·
> Option 1 is bad because: (a) it involves an unnecessary copy constructor invocation Shouldn't rvalue move semantics kick in and prevent the copy?
by santaclaus 12y ago
> Option 1 is bad because: (a) it involves an unnecessary copy constructor invocation
Shouldn't rvalue move semantics kick in and prevent the copy?
- vickychijwani 12y agoAgreed. I'll add a note. There's still the slicing though.
- nostrademons 12y agoFor slicing, the general rule in C++ is whenever you have a value object, polymorphism does not apply. A value object is always whatever its compile-time type is - after all, it's just a value, it can't represent some other "thing" that's off in some other memory space. Polymorphism only applies with pointers and references. Remember this rule and the throws behavior makes perfect sense, as do a lot of other C++ gotchas.