Ron Natalie wrote:
"Thomas Baier" <th****@tho-bai.de> wrote in message
news:3f**********************@newsread4.arcor-online.net... > temp = myclass;
This line isn't legal. I don't know what you mean by this.
*this = temp; //this line
produces no error by the compiler
//but in fact
temp and this
aren't the same
This is not illegal though of dubious use. It invokes operator= to copy
temp to *this (or whatever else your copy-assignment operator does).
To make it more concrete: I've got a binary tree class and I've got a method
that balances the tree. This method is of type void. So I'm creating a new
temporary tree out of the members of the original tree that is balanced and
then I want to copy the temporary tree into the original tree object, but
that doesn't work.
I've got some code like
void tree::balancing()
{
tree temp;
//creating balanced tree in temp with the nodes of "this"
showTree(temp); //shows the correct balanced tree
*this = tree;
showTree(*this); //show a wrong tree with neverending loop cause one tree
is node of itself
}
So what should I do instead of this to get it working?