Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Option 1 is bad because: (a) it involves an unnecessary copy constructor invocation

Shouldn't rvalue move semantics kick in and prevent the copy?



Agreed. I'll add a note. There's still the slicing though.


For 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: