Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 #55420 is a reply to message #55412] Mon, 09 November 2020 20:46 Go to previous messageGo to previous message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi 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?

Thanks and best regards,

Tom
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message icon10.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Layout Designer has been documented (TheIDE)
Next Topic: 2nd price!
Goto Forum:
  


Current Time: Sat Apr 27 01:46:14 CEST 2024

Total time taken to generate the page: 2.99266 seconds