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   |
|
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
|
|
|
Goto Forum:
Current Time: Wed Apr 30 23:42:56 CEST 2025
Total time taken to generate the page: 0.00923 seconds
|