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 #23596 is a reply to message #23578] Tue, 03 November 2009 14:21 Go to previous messageGo to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1791
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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
 
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: Wed Apr 30 23:42:56 CEST 2025

Total time taken to generate the page: 0.00923 seconds