About initialization list
1 2 3 4 5 6 7 8 9 10 11
|
Lista ()
{
// at this point all the members were already constructed (using the default constructor)
testa = NULL; //this is assignment
//...
}
Lista():
testa(NULL) //initialization (construction)
{
//...
}
|
Now there is no difference, but consider the case when you have a member variable that does not have a default constructor. Your approach will fail, you need to use initialization lists. The same can be said when you have inheritance and you need to construct your base object, you need to use initialization lists.
So better learn them now.
> Now the concatenate function is in the main directly.
You could have simply passed the parameter by reference
void concatenate (Lista l, Lista m, Lista &n);
Also, note that your current copy constructor and assignment operator (provided by the compiler) are performing a
shallow copy instead of a
deep copy.
You'll need to code a destructor too or you'll have memory leaks.
> The i\o expexted is as example insert 1, insert 3, in first list and insert 2 in second, the concatenated shuold be 1 2 3
Your code has a (bothersome) menu. I lose too much time with it, when just want to test your program.
What I want is something like
example input:
expected output:
current (erroneous) output: