【发布时间】:2020-07-15 03:38:36
【问题描述】:
class Node {
public:
int key;
Node *parent;
std::vector<Node *> children;
Node() {
this->parent = NULL;
}
void setParent(Node *theParent) {
parent = theParent;
parent->children.push_back(this); // I can't understand this.
}
};
在函数setParent中,在parent->children.push_back(this)中,我们为什么要传递this作为参数,它会做什么?
【问题讨论】:
-
this 基本上是一个指向调用对象的指针。
-
这能回答你的问题吗? What is the 'this' pointer?
-
这能回答你的问题吗? What is the 'this' pointer?