On 17 September 2014 18:15, Andy Falanga (afalanga) wrote: >> That reinterpret_cast looks dodgy to me, accessing the object through a >> different type is undefined behaviour. What's wrong with doing it >> safely? >> >> Flag operator &=(Flag& f1, Flag f2) { >> unsigned int i = f1; >> i &= static_cast<unsigned int>(f2); >> return f1 = static_cast<Flag>(i); >> } > > Ha, nothing except my thinking that, because I was casting a reference, I had to use reinterpret_cast<>. Well yes, if you want to cast T& to X& and T and X are not related by inheritance then you do need to use reinterpret_cast, but that should make you think "maybe this is not a valid cast, maybe I shouldn't do it" rather than "if I use reinterpret_cast the compiler doesn't complain so it must be the way to go".