I'm using a recursive implementation which has a method toString() that returns a string (concatenated or appended) by all the values in my tree. Unfortunately when I try using "+=" or the old "string = string + otherString" all it seems to do is override the original. Giving me a single value instead of all of them. When I replace it with "cout << " then all the values print. I have #include <string>, so I should be able to do that right?
Code://Note: toString() returns a string representation of any value being stored in the tree // such as integers, floats etc... and works fine. string Node::print() { string result; //travel left if( this->getLeft() != NULL ) { this->getLeft()->print(); } //Keep track of values result += this->getValue()->toString(); //doesn't store all the values //cout << this->getValue()->toString(); //prints all the values //travel right if( this->getRight() != NULL ) { this->getRight()->print(); } return result; }



LinkBack URL
About LinkBacks



CornedBee