|
|
Home » Community » PR, media coverage, articles and documentation » Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework... [message #55424 is a reply to message #55420] |
Mon, 09 November 2020 22:05 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
Tom1 wrote on Mon, 09 November 2020 20:46Hi Mirek!
Thanks!! Great article!
Although I started learning U++ 2006, I'm still learning... : An Array can actually hold objects of inherited classes! This was interesting and very useful for my needs. However, I could not figure out how to make serialization/deserialization of this work correctly. Here's my failed test of that:
using namespace Upp;
class A{
public:
int a;
A(){
a=1;
Cout() << "A+\n";
}
virtual ~A(){
Cout() << "A-\n";
}
virtual void Serialize(Stream &s){
s % a;
}
virtual void Print(){
Cout() << "A: " << a << "\n";
}
};
class B: public A{
public:
int b;
B(){
b=2;
Cout() << "B+\n";
}
~B(){
Cout() << "B-\n";
}
virtual void Serialize(Stream &s){
A::Serialize(s);
s % b;
}
virtual void Print(){
Cout() << "B: " << a << ", " << b << "\n";
}
};
CONSOLE_APP_MAIN{
Array<A> v;
v.Create<A>();
v.Create<B>();
v.Create<B>();
v.Create<A>();
Cout() << "Printing array...\n";
for(int i=0;i<v.GetCount();i++) v[i].Print();
Cout() << "Storing to file...\n";
StoreToFile(v,GetHomeDirFile("Test.bin"));
Cout() << "Clearing...\n";
v.Clear();
Cout() << "Loading from file...\n";
LoadFromFile(v,GetHomeDirFile("Test.bin"));
Cout() << "Loaded from file...\n";
Cout() << "Printing array...\n";
for(int i=0;i<v.GetCount();i++) v[i].Print();
}
What is the correct way to do this?
Seriously, you cannot... Sorry that I might have created that impression.
I mean, you definitely can solve this, but not with out-of-box Array::Serialize. You need to provide your own serialization there and store the type on saving, load on loading.
In reality, this is not needed very often...
Mirek
|
|
|
|
|
Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: mirek on Mon, 09 November 2020 12:29
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: Oblivion on Mon, 09 November 2020 16:16
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: mirek on Mon, 09 November 2020 16:33
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: Xemuth on Mon, 09 November 2020 17:24
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: Didier on Mon, 09 November 2020 20:48
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: koldo on Mon, 09 November 2020 21:10
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: Tom1 on Mon, 09 November 2020 20:46
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: mirek on Mon, 09 November 2020 22:05
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: Tom1 on Tue, 10 November 2020 10:03
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: Klugier on Tue, 10 November 2020 15:24
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: mirek on Tue, 10 November 2020 15:37
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: wimpie on Tue, 10 November 2020 22:53
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: jimlef on Fri, 13 November 2020 17:23
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: mirek on Sun, 15 November 2020 09:41
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: Klugier on Tue, 17 November 2020 00:30
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: mirek on Tue, 17 November 2020 00:39
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: mirek on Tue, 17 November 2020 00:54
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: Klugier on Tue, 17 November 2020 01:09
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: mirek on Tue, 17 November 2020 10:10
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: mirek on Wed, 18 November 2020 12:22
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: Oblivion on Wed, 18 November 2020 14:35
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: mirek on Wed, 18 November 2020 15:47
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: mirek on Sun, 22 November 2020 17:49
|
|
|
Re: Some Shocking Facts You Probably Didn't Want to Know about U++ Framework...
By: 281264 on Mon, 22 March 2021 20:51
|
Goto Forum:
Current Time: Thu Mar 28 23:06:07 CET 2024
Total time taken to generate the page: 0.01908 seconds
|
|
|