Sunday, October 23, 2011

More reasons why C++ gives me headaches

This gem is from the wikibook More C++ Idioms, to get the address without needing a valid operator&. Enjoy the cast once, cast twice, wait, I didn't mean char at all goodness.


template
T * addressof(T & v)
{
return reinterpret_cast(& const_cast(reinterpret_cast(v)));
}

1 comment: