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

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: