mlimber <ml*****@gmail.comwrote:
>we*****@yahoo.com wrote:
>As part of simple serialization, I like to determine which is the right
way to do:
flatten a class containing flat C-structs with some member functions or
just plain C-structs. We need to store those data as context in shared
memory. I just want to know what is pro and cons for this idea:
class Context
{
public:
memFun1();
memFun2();
Data1 data1;
Data2 data2;
}
OR
struct Context
{
Data1 data1;
Data2 data2;
}
>Huh? You can serialize a class/struct with private/protected/public
data and with/without member functions just as well as you can
serialize a C-style, POD struct. What's the question again?
I think the question may have been: given the first class, should
one create the second struct before serializing the data out to
wherever it's going.
If so, I think the answer is no -- why create a new struct, when
you can just serialize the data in the existing class. You do
not need to serialize the member functions as they already redundantly
exist in the class declarations at each end of the serial connection.
(If that's not the question, then ignore what I wrote above.)
Steve