PDA

View Full Version : Need help in c++ code



sheree
03-22-2008, 12:29 PM
Hello everyone,
I am new member, and I had problem
I wrote a code which needed a kdtree data structure for nearest neighbour algorithm, so I found a code written in c++, but in there I found " this " variable which I haven't seen like it before and I don't know what does it mean as well. Simply the code is a lass that have find parent function like that:

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

so if any one know what " this " means please tell me or may be you know where can I find a c++ documentations that illustrates it .

Thank in advance for any kind of help

Ezekiel
03-23-2008, 04:30 AM
In C++ OOP, 'this' is used in a member function as a pointer to the object that was used to call the function.

In the case of your code, the object would be of KKDTEMPLATE KDNODE* type [I think], and the member function is FindParent(Xtype* x0).