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 » U++ Library support » U++ Core » Deepcopying One container
Re: Deepcopying One container [message #23599 is a reply to message #23596] Tue, 03 November 2009 19:45 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13984
Registered: November 2005
Ultimate Member
dolik.rce wrote on Tue, 03 November 2009 08:21

luzr wrote on Mon, 02 November 2009 11:14


Surprisingly, yes, we can provide polymorphic copies - by overloading DeepCopyNew.

That can be simplified by using PolyDeepCopyNew, using virtual
Copy method.

In reality, I have never really used polymorphic deep copy, it looks a little bit tricky to me. What is your usage scenario?

Mirek


PolyDeepCopyNew works like a charm! Thank you very much Mirek, the solution was trully genial in its simplicity.

Just for future reference, the solution is something like this:
#include <Core/Core.h>
using namespace Upp;

class A: public PolyDeepCopyNew<A>{
public:
	virtual void DoSmthng(){Cout()<<"I'm A.\n";};
	virtual A* Copy()const{return new A;}
};
class B:public A{
public: 
	virtual void DoSmthng(){Cout()<<"I'm B.\n";};
	virtual B* Copy()const{return new B;}
};

CONSOLE_APP_MAIN{
	One<A> a=new A;
	One<A> b=new B;
	One<A> c;
	
	c<<=a;
	c->DoSmthng();
	
	c<<=b;
	c->DoSmthng();
}


Honza


IMO, the example is a very little bit misleading - Copy should deepcopy some content...

Mirek
 
Read Message icon5.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: *Map::IsPicked() is missing
Next Topic: Latest change on FileMapping::Map() wrong for win32
Goto Forum:
  


Current Time: Sun Jun 16 12:12:36 CEST 2024

Total time taken to generate the page: 0.02461 seconds