Questions tagged [shallow-copy]

A shallow copy of an object is a duplicate that may not be fully independent of the original, in the sense that any references / pointers it holds to other objects refer to the same objects that the original's do. Use this tag for questions regarding implementing or using shallow copying methods.

Shallow copying is a process by which an object is duplicated to create a copy that may not be wholly independent of the original. Also known as "field by field" copying, this differs from deep copying with respect to the treatment of references / pointers to other objects: shallow copying copies the references / pointers held by the original, whereas deep copying makes a deep copy of each referenced object, too. Shallow copying is "shallow" in the sense that it copies only the original object itself, not any appearing deeper in its reference graph.

Related tags

Links

394 questions
-3
votes
1 answer

C++ parent object loses the internal data of the child object, something wrong related to copy constructor or passing by reference?

My question is explained in the example below. It is weird that the parent object loses the internal data of its child object, if the parent object is instantiated before the child object populates its internal data. The code has a TicketService,…
-3
votes
1 answer

Remove from one list impact it's copy [python 2.7]

I created a copy of a list. When an item was removed from one copy - it was removed from the original as well. a = ['alpha', 'beta', 'gamma', 'delta'] b = a b.remove('alpha') print 'A list is', a print 'B list is', b How should I create an…
DarkLight
  • 79
  • 3
  • 16
-3
votes
2 answers

"Double free or corruption" error not thrown when code lines rearranged

I am using shallow copy to copy one object to another object and when main() goes out of scope destructors are called and error ": double free or corruption (fasttop):" is thrown which is perfectly fine as I am using shallow copy. Now when I am…
-3
votes
1 answer

Is there a way to make a shallow copy of a constant struct to a non-constant struct?

I want to make a shallow copy on an entire struct which has the constant deceleration. But I want the struct that I am copying too to be non constant. This is what I have done so far which is producing an error: struct Student{ char *name; …
Brandon
  • 401
  • 5
  • 20
1 2 3
26
27