I wonder if the following works (I guess not, otherwise everyone would've used it, right? :-)). I tried them on simply classes I wrote, but I wonder if it works for the general case. One can write a to_stream()
function for a generic class by simply copying the memory of the object to CHAR[]
?
For instance:
memcpy(buf, (void*)&object1, sizeof(object1))
Now, can i write a from_stream()
function for a generic class by simply copying the memory from CHAR[]
to the object?
For instance:
memcpy(&object2, buf, buf_len) // or using sizeof(C) instead of buf_len.
p.s. I AM NOT going to use this code in an actual product, this is simply a question to understand better the internals. Thanks :-)