|
|
Home » U++ Library support » U++ Core » Serialize of derived classes
Serialize of derived classes [message #36357] |
Tue, 22 May 2012 11:15  |
 |
koldo
Messages: 3432 Registered: August 2008
|
Senior Veteran |
|
|
Hello all
By doing the enclosed code MyClass data is serialized but MyClassA is not used.
How it has to be done to store the data of MyClassA including the data of the parent MyClass?
struct MyClass {
MyClass(int data) : data(data) {};
int data;
void Serialize(Stream& stream) {stream % data;}
};
struct MyClassA : public MyClass {
MyClassA(int dataA) : dataA(dataA) {data = dataA*2;};
int dataA;
void Serialize(Stream& stream) {stream % dataA; MyClass::Serialize(stream);}
}
struct MyClassList {
Array<MyClass> elems;
void Serialize(Stream& stream) {stream % elems;}
};
...
elems.Add(new MyClassA(12));
StoreToFile(elems, "myfile");
Best regards
Iñaki
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Tue Apr 29 05:36:55 CEST 2025
Total time taken to generate the page: 0.00983 seconds
|
|
|