Hello everyone...
I'm confused on what exactly is happening when you pass somthing by pointer reference if thats how you say, *&.
For instance here is the function:
If i had this class:Code://I think this function is suppose to return a valid pointer, pointing to the root after its built template<typename T> void BuildTree(TreeNode<T>*& root, const string& epxression) { root = NULL; }
Code:template<typename T> struct TreeNode { TreeNode(const T& value, TreeNode<T>* left = NULL, TreeNode<T>* right = NULL) { Value = value; Left = left; Right = right; } T Value; TreeNode<T>* Left; TreeNode<T>* Right; bool IsLeaf() const { return Left == NULL && Right == NULL; } };
WOuld I use the function like this?
So really my question is, if thats what I should be doing in the main function and also, why is it *& and not just &? or not just *?Code://main.cpp TreeNode<char> *root = new TreeNode<char>; std::string expression = "a+b*4"; BuildTree(root,expression);
Thanks, if you have a website that explains that, that would be helpful as well!




Reply With Quote