【发布时间】:2023-03-20 14:46:01
【问题描述】:
我有一个三叉树/图,它的一个孩子需要它的孩子指向它的父母。
class TTree
{
public:
tTree();
~tTree();
TTree *back;
TTree *forward;
TTree *left;
TTree *right;
int numsteps;
bool ifVisited = false;
bool ifExpended = false;
void insert(int steps, TTree *direction);
}
在插入中*back 必须指向自身。
TTree::insert(int steps, TTree *direction){
this->direction = TTree();
this->direction->numsteps = steps;
this->direction->back = this;
this->direction->forward = NULL;
this->direction->left = NULL;
this->direction->right = NULL;
}
我想出了这个,但我不确定 this->direction->back = this 右手边的 this 是否会指向自己作为调用函数的对象,或者它会引用 this->direction->back 的左手边语句
【问题讨论】:
-
'this' 是调用该方法的实例。它与您提到的左值无关。
标签: c++ pointers object graph this