I have the following template function used to dump data of any standard type into a binary output stream.
template<typename T> static void
dump ( const T& v, ostream& o ) {
o.write ( reinterpret_cast<const char*>(&v), sizeof(T));
}
Instead of the reinterpret_cast I could also use a C-style (const char*). Is there any particular reason to use reinterpret_cast? I read a few other posts where reinterpret_cast was frowned upon. But the above usage is legal and cannot be replaced with anything else, right?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…