@Athar
Maybe we first should argue more practical than technical? Because the discussion becomes a little bit too technically for beginners - oh not for me.
I think, there is some confusion about, what is an object and what is a container.
For example I have a horse. And this horse stays in a stable, which is just fitting for the horse. And at the door of the stable is a label with the name of the horse.
The question is now, what's the object? Is it the stable and the horse is it's content? Or is it the horse and the stable is it's container?
My opinion is, it's the horse.
If the stable is old, it could break down, so that it is destroyed. And if this happens, also the horse will be dead (also become destroyed). If I know this, I could move the horse to a new fine stable, before this happens. And when the old stable collapses, my horse will be well.
It seems to me, that some people think, because the stable has a label with the name of the horse at the door, the stable would be the horse, and when it collapses, the horse has to be destroyed.
Maybe you can understand, that I don't like such ideas about destroying my horse, when there is no such neccessity.
And maybe, we should imagine variables not as the objects, but the containers of objects. If we have a basket with the cat inside, so we also have the cat.
And the compiler should be a tool, what does, what we want.
Sometimes I want a new basket with a new cat. So I write:
CatClass NewBasket = CatClass("NewCat");
Maybe it's easy to bring me this. Only have to go to a cat shop, buy a new basket and a new cat, put the cat in the basket and bring it.
If I have already a basket, this job will become more difficult, for example:
CatClass MyBasket;
MyBasket = CatClass("New Cat");
My basket is at home. And you don't have it. How can you transport the cat? Oh that's your problem, not mine. I only want, that you bring the cat and put it in my basket.
And then you come and bring me a dead cat? And tell me is has to be so, and this would exactly be the correct way, because I already had a basket?
No I was wrong. You bring me a nice living cat. But you used another basket for the transport. And because the cat made this basket dirty, you throw it away and destroy it. And because you think - I don't reason why - the cat would have been still inside and also should be dead now, you come back and kill my cat.
This is really very difficult to understand for me. But I have some reason to think, that you are not quite right. But now I have to sleep.
Maybe tomorrow we know something more about this.
Oh I found an interesting web site:
http://www.learncpp.com/cpp-tutorial/911-the-copy-constructor-and-overloading-the-assignment-operator/
Here the author wrote:
The purpose of the copy constructor and the assignment operator are almost equivalent — both copy one object to another. However, the assignment operator copies to existing objects, and the copy constructor copies to newly created objects. |
And further he wrote:
If a new object has to be created before the copying can occur, the copy constructor is used.
...
There are three general cases where the copy constructor is called instead of the assignment operator:
...
2. When passing an object by value.
3. When an object is returned from a function by value. |
This means, your assumptions, that it should be the operator= were not true.
Now we should find also something about the lifetime of an object.
My opinion is, the cat should not have been copied but moved. And on the stack is only the empty basket. And it still is alive and it's lifetime hasn't ended. Maybe we can find more about this somewhere.