Some of my coursework material suggests using a reinterpret cast:To serialize an object. Is this as bad of an idea as I think it is?Code:outfile.write(reinterpret_cast <char*> (&Object_name), sizeof (Object_type) );
Some of my coursework material suggests using a reinterpret cast:To serialize an object. Is this as bad of an idea as I think it is?Code:outfile.write(reinterpret_cast <char*> (&Object_name), sizeof (Object_type) );
Absolutely. How well would that work for this object:Is this as bad of an idea as I think it is?
It is way better to let objects serialize themselves. For instance, it is common to serialize objects as XML these days, so you could make your class have a ToXML() function.Code:class WontSerialize { WontSerialize(void) { pBuffer = new char[100]; } char* pBuffer; };
there exist bosst::serialisation and it is able to serialize to xml, binary and text.