Hello everyone,
I am a new memeber, and I need help in c++ code.
Actually I had a code that need kd tree data structure in order to find the nearest neighbour, so I found a kd tree that had been written in c++ as class and there is a function which specialized to find the parent of any given point and it starts with assigning a pointer by " this " and actaully I didn't understand it and in the mean time I didn't find good resources that explaine what does " this " means in general..is it special for classes or just stansered viriable and what does it mean
The function looks like that :

KDTEMPLATE
KDNODE*	KDNODE::FindParent(Xtype* x0)
{
    KDNODE* parent ;
    KDNODE* next = this ;
    int split ;
    while(next)
    {
        split = next->axis  ;
        parent = next ;
        if(x0[split] > next->x[split])
            next = next->Right ;
        else
            next = next->Left ;
    }
    return parent ;
}

The entire stuff that related with this code is in the following link:

http://www.codeproject.com/KB/architecture/KDTree.aspx?display=Print

I thank you all in advance for any kind of help or advices

this is apointer to the current object of the class which function is member of.

i will be pleasure if i help you

this is a hidden parameter that is passed to every non-static method of a c++ class. It is used to point to a specific instance of a class and all its data object. In your specdific problem FindParent() is called from a specif node in the list, and the this parameter that is passed to that method by c++ is a pointer to that node.

thanks farag, thanks Ancient Dragon,
but Ancient Dragon, I still wundering about that pointer.
If I understood well, then this will point to the node that I wan to find its nearest neighbour,......but then how can I find its parent while it is not a node belongs to the kd tree , as it mentioned in FindParent()
I'll appricate any more detail.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.