Friend class and pointer function
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Friend class and pointer function

Threaded View

  1. #1
    Join Date
    Jul 2008
    Posts
    13

    Friend class and pointer function

    Hi! I need help with understanding this block of code, particullary this line: *getLeftChild() { return this - _child; }

    Code:
    public class UpperNode
    {
    BOX _box;
    int _child;
    
    FORCEINLINE UpperNode *getLeftChild() { return this - _child; }
    ...
    
    };

    Here I have this function:

    Code:
    void
    UpperNode::visulization(int level)
    {
    	if (isLeaf())
    		_box.visulization();
    	else
    		if ((level > 0)) {
    			if (level == 1)
    				_box.visulization();
    			else
    			if (getLeftChild())
    				getLeftChild()->visulization(level-1);
    			if (getRightChild())
    				getRightChild()->visulization(level-1);
    		}
    }
    It also makes calls for "getLeftChild()";
    But I see that getLeftChild expects function pointer, and I absolutely have no clue where "this" comes from inside function body.

    (return this - _child) - "this" has to be integer.
    Or, if we gave pointer, and "this" is reffering to some UpperNode, then I can't understand to which one, I have no UpperNode array defined or something. So if this functions is actually scaling pointer address, then scaling where to? I could comprehend it, if I had some array of UpperNodes, but not just class. I have UpperNodes array defined in other friendly class, but don't think they are related
    Last edited by RyuMaster; March 9th, 2013 at 04:30 AM.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center