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
icon5.gif  Deepcopying One container [message #23574] Mon, 02 November 2009 09:37 Go to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi,

I've met following problem with polymorphic classes in One containers. Consider following code:
#include <Core/Core.h>
using namespace Upp;

class A{
public: 
	virtual void DoSmthng(){Cout()<<"I'm A.\n";};
};
class B:public A{
public:
	virtual void DoSmthng(){Cout()<<"I'm B.\n";};
};

CONSOLE_APP_MAIN{
	One<A> a=new A;
	One<A> b=new B;
	One<A> c;
	
	c<<=a;
	c->DoSmthng();
	
	c<<=b;
	c->DoSmthng();
The output of this is
I'm A.
I'm A.
It surprised me at first, but after looking in the implementation of operator<<=, I understood that this is to be expected (that is not a bug).

The question is: Is there some workaround to make a copy of One without loosing the information about the type it stores? I mean to make it work same way as if you do
	c<<=a;
	c->DoSmthng();
	
	c<<=b;
	c->DoSmthng();
but without a and b beeing picked. Is that even posible?

Thanks for any responses.
Regards,
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: Tue May 14 01:49:25 CEST 2024

Total time taken to generate the page: 0.03080 seconds