Bit Byte wrote:
Quote:
Suppose I have a data variable defined thus:
>
typedef std::vector<std::pair<std::string,std::string InfoVector ;
>
I have written a template function to generalize serialization:
>
template <class Tstd::ostream& Serialize(std::ostream& out, const T&
value)
{
out.write(reinterpret_cast<const char*>(&value), sizeof(T)) ) ;
}
>
Can I pass InfoVector to my template function (or do I need a partial
specialized template ?). Any clarification on this issue will be very
helpful
Your writing the address of your InfoVector (plus some garbage since
you are writing sizeof(InfoVector) bytes which is greater than and
address). As Julian points out, this is not serialization. You would
need to step through the vector and serialize the value (not reference)
of each pair respectively in such a way as a copy of the original
vector can be pieced back together again. Java has some langauge
support for this, I think Boost has some libraries for C++, however, I
never used them.