CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Sep 2004
    Posts
    236

    Arrow confused on what passing by *& is doing!

    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:
    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;
    
    }
    If i had this class:
    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?

    Code:
    //main.cpp
    TreeNode<char> *root = new TreeNode<char>;
    std::string expression = "a+b*4";
    
    BuildTree(root,expression);
    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 *?

    Thanks, if you have a website that explains that, that would be helpful as well!
    Last edited by voidflux; March 22nd, 2007 at 10:47 AM.
    Computer Science/Engineering
    @ PSU
    Co-oping with IBM's zSeries team! wee
    VS 2005.net
    http://www.personal.psu.edu/css204/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured