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 » ONE and assignement
ONE and assignement [message #50101] Sat, 28 July 2018 09:48 Go to next message
mdelfede is currently offline  mdelfede
Messages: 1259
Registered: September 2007
Senior Contributor
Hi,

I'm right that One<> is missing those operators?

	template <class TT>
	void        operator=(One<TT>&d) = delete;

	template <class TT>
	void        operator=(One<TT> const &d) = delete;


In an application I've noticed that if I do :

	One<String> A = new String("pippo");
	One<String> B;
	B = A;
	Cout() << "*A = " << *A << "\n";
	Cout() << "*b = " << *B << "\n";


The internal pointer is copied, NOT picked, and NO COMPILER ERROR IS GENERATED, so when A and B get destroyed the pointer is
double freed and I get a violation access error.
Adding the above operators brings a compiler error, which is the correct behaviour, IMHO.

Ciao

Max
Re: ONE and assignement [message #50103 is a reply to message #50101] Sat, 28 July 2018 11:35 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11843
Registered: November 2005
Ultimate Member
Thanks, correct, fixed (also with Any and Bits)
Re: ONE and assignement [message #50104 is a reply to message #50103] Sat, 28 July 2018 14:46 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1259
Registered: September 2007
Senior Contributor
Thank you!

BTW, I've seen that One<> is also missing DeepCopyNew()... when I use operator <<= to get
a deep copy of contained object I get a compiler error.
Re: ONE and assignement [message #50105 is a reply to message #50104] Sat, 28 July 2018 17:06 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11843
Registered: November 2005
Ultimate Member
mdelfede wrote on Sat, 28 July 2018 14:46
Thank you!

BTW, I've seen that One<> is also missing DeepCopyNew()... when I use operator <<= to get
a deep copy of contained object I get a compiler error.


Uhm, that is leftover from pre c++11 Core. DeepCopyNew was means to allow polymorphic copy, but I do not remember anybody ever using it. For current core it is replaced (in Array) with simple clone (non-polymorphic), so that is how I have fixed it here...

Mirek
Re: ONE and assignement [message #50107 is a reply to message #50105] Sun, 29 July 2018 10:22 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1259
Registered: September 2007
Senior Contributor
So the only way to deep copy an One<> is to use:


One<AClass> A = new AClass(1, 2, 3);
One<AClass> B;

B = new AClass(*A, 1);



Assuming that AClass has a deep copy constructor, right ?
I'm missing the polymorfic deep copy...
Btw, also the clone() complains about missing DeepCopyNew.
Re: ONE and assignement [message #50108 is a reply to message #50107] Sun, 29 July 2018 10:35 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11843
Registered: November 2005
Ultimate Member
mdelfede wrote on Sun, 29 July 2018 10:22
So the only way to deep copy an One<> is to use:
Btw, also the clone() complains about missing DeepCopyNew.


Now that is really weird, as "DeepCopyNew" identifier does not exist in U++ sources...
Re: ONE and assignement [message #50109 is a reply to message #50108] Sun, 29 July 2018 11:18 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1259
Registered: September 2007
Senior Contributor
Core/Other.h, line 69, in my tree, which is up-to-date with svn repo Wink
Re: ONE and assignement [message #50111 is a reply to message #50109] Sun, 29 July 2018 20:21 Go to previous message
mirek is currently offline  mirek
Messages: 11843
Registered: November 2005
Ultimate Member
Oops, sorry, forgot to commit.

Mirek
Previous Topic: RegExp this'n that
Next Topic: [solved] Extensions to Xmlize for arrays
Goto Forum:
  


Current Time: Wed Apr 24 23:50:43 CEST 2019

Total time taken to generate the page: 0.00670 seconds