We can clearly see that the OrderedLinkedList has no data members of its own. The members of UnorderedLinkedList should preferably be private, not protected.
When an OrderedLinkedList object is created:
1. Allocate enough memory for the whole object
2. Initialize the UnorderedLinkedList subobject
2a Initialize the members of UnorderedLinkedList (data* and link)
2b Execute the body of UnorderedLinkedList<Type>::UnorderedLinkedList
3. Initialize members of OrderedLinkedList (none)
4. Execute the body of OrderedLinkedList<Type>::OrderedLinkedList
On destruction:
1. Execute the body of OrderedLinkedList<Type>::~OrderedLinkedList()
2. Destruct members of OrderedLinkedList (none)
3. Destruct the UnorderedLinkedList subobject
3a. Execute the body of UnorderedLinkedList<Type>::~UnorderedLinkedList()
3b. Destruct the members of UnorderedLinkedList (data* and link)
4. Deallocate the memory block
*) The Type naturally may have constructor, destructor and base class(es) of its own
Your design has a serious flaw:
1 2 3 4
|
OrderedLinkedList<int> order;
order.insertFirst( 7 );
order.insertFirst( -1 );
order.insertFirst( 42 );
|
That is syntactically legal, but is the list
ordered?