P
Pep
Think it is about time I got this straight in my head, with the help
of you guys of course
So a struct is a collection of data members as is a class, where a
class default scope is private and a struct default scope is public.
All well and good so far.
If I send the address of a struct or class to a function within my
program everything is well and good, obviously all of the class/
struct, i.e. the members, methods and vtable exist in my program.
Now here is the point I get a little fuzzy, what happens if I want to
serialize the struct/class. Assuming I send the address of the struct/
class and it's size() as parameters to my serialize function, I can
effectively write the size() number of bytes from the address
parameter to a file. What happens with the methods and vtable of a
struct/class when you serialize it?
I know that I can easily allocate a region of memory and cast it to a
struct/class and effectively use it as an instantiated instance of the
struct/class. So I suspect the obvious answer is that the methods and
vtable are discarded and reapplied when the memory region when cast
against a struct/class.
Presumably, the only way a struct/class can be deserialized is by a
function that knows the declaration of the struct/class?
So is what I outlined correct in terms of the c++ standard or only for
certain c++ compilers that may have extended things?
of you guys of course
So a struct is a collection of data members as is a class, where a
class default scope is private and a struct default scope is public.
All well and good so far.
If I send the address of a struct or class to a function within my
program everything is well and good, obviously all of the class/
struct, i.e. the members, methods and vtable exist in my program.
Now here is the point I get a little fuzzy, what happens if I want to
serialize the struct/class. Assuming I send the address of the struct/
class and it's size() as parameters to my serialize function, I can
effectively write the size() number of bytes from the address
parameter to a file. What happens with the methods and vtable of a
struct/class when you serialize it?
I know that I can easily allocate a region of memory and cast it to a
struct/class and effectively use it as an instantiated instance of the
struct/class. So I suspect the obvious answer is that the methods and
vtable are discarded and reapplied when the memory region when cast
against a struct/class.
Presumably, the only way a struct/class can be deserialized is by a
function that knows the declaration of the struct/class?
So is what I outlined correct in terms of the c++ standard or only for
certain c++ compilers that may have extended things?