|FROM ||Ruben Safir
|SUBJECT ||Subject: [NYLXS - HANGOUT] C++ Workshop, Linked List Workshop - usenet article.
From: Yannick Tremblay
Subject: Re: Destructors can copying objects
Date: Wed, 6 Apr 2011 11:12:43 +0000 (UTC)
Organization: A noiseless patient Spider
Content-Type: text/plain; charset=us-ascii
Injection-Date: Wed, 6 Apr 2011 11:12:43 +0000 (UTC)
User-Agent: slrn/0.9.9p1 (Linux)
Xref: panix comp.lang.c++:1083058
On 2011-04-05, Ruben Safir wrote:
> But I'm distressed at this point because I don't want two copies of
> the nodes. I want one series of nodes, which are created in free
> on the stack, handled in all possible scopes. The nodes themselves
> 'self aware" of their positions in the list in that they have the
> information of they're position in the nodes. The List object itself
> does nothing more that communicate with the nodes. If I copy the List
> Object, I don't want to duplicate the nodes as well. They're on the
> heap, and then can stay there.
Are you sure about the behaviour you want?
You have a List.
The list contains Nodes.
The Nodes contain a pointer to some data.
What behaviour do you want when you copy a list?
What behavious do you want when you copy a node?
What behaviour do you want when you destroy a list?
What behaviour do you want when you destroy a node?
Don't worry about optimization for now. Worry about correctness and
Does the Node own the data it points to?
- If yes: then the node most delete the data when the node gets
- If no: the node only refers to the data that is external. The node
can go away without affecting the data. Lifetime management of the
data is done separately.
Should modifying a copy of a list affect the original list?
// add ten element to list1;
assert(list1.size() == 10);
List list2 = list1; // Create a copy
assert(list2.size() == list1.size()); // definite at this point
// remove 2 element from list2
assert(list2.size() == 8);
// What about list1? Should it still contain 10 elements or 8?
Does the list owns the nodes it contains?