Original Post
EDIT: Nevermind, my types were getting mixed up inbetween writes/reads. [rolleyes] Since I've wasted your time, here's the overloaded templates for references and pointer types for your perusal: I have function templates to write and read and to/from binary streams. [Edited by - stylin on October 17, 2005 11:18:46 AM]
namespace utility { // generic stream reading/writing functions
template< typename T >
void write_to_stream( std::ostream & s, const T & source ) {
s.write( reinterpret_cast< const char * >( &source ), sizeof( source ) );
return;
}
template< typename T >
void write_to_stream( std::ostream & s, T * const & source ) {
s.write( reinterpret_cast< const char * >( source ), sizeof( *source ) );
return;
}
template< typename T >
void read_from_stream( std::istream & s, T & destination ) {
s.read( reinterpret_cast< char * >( &destination ), sizeof( destination ) );
return;
}
template< typename T >
void read_from_stream( std::istream & s, T * const & destination ) {
s.read( reinterpret_cast< char * >( destination ), sizeof( *destination ) );
return;
}
}