Essentially, the 'Sequence' below uses linked lists to store data. If 'result' refers to the same sequence as 'seq1' or 'seq2', I want 'result' to refer to a new sequence. This new sequence can be default constructed (no copy of 'seq1' or 'seq2' is required). I can't seem to do this correctly. Also, the prototype of the function cannot be altered.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void fun(const Sequence& seq1, const Sequence& seq2, Sequence& result)
// Check for reference to same sequence. If they are the same,
// create new sequence for 'result' to refer to
if ((&seq1 == &result) || (&seq2 == &result))
// How do I create a new Sequence that wont be destroyed?
// All I need is for 'result' to now refer to an empty sequence.
// The following method is incorrect.
Sequence* tmpSeq = new Sequence;
&result = *tmpSeq;