PDA

View Full Version : Copy an Object



Qiieha
1st July 2011, 16:18
Hi
I develop a programm where the user is able to build a sql query. A query can consist of several selections. A Selection consists of several conditions.
Now I want to develop copy and paste function. The user should be able to copy and paste a selection.

Now my question:
whats the common way to copy an object (in my case i want to copy the conditions).
the copied objects should be on a different place on the heap.

Should I implement a copy-method? Or a copyclass which creates new Objects?

thank u for help

stampede
1st July 2011, 16:28
If it's a value based class, then you can implement operator = and copy constructor, it will be sensible to copy the objects this way.

the copied objects should be on a different place on the heap.
In that case you can provide a "copy" or "clone" method for your class, returning new object with the same properties as copied object.

Qiieha
11th July 2011, 08:15
i know it's a bit late, but i was on holiday = )

thank u for your reply. I have a lot of objects, so i'll implement a clone method. I think it's the better way, isn't it ?