Как сделать указатель в методе класса, указывающего на объект, к которому вызывается метод?
Я хочу определить указатель в теле открытого метода класса ипусть он указывает на экземпляр объекта, к которому вызывается метод.
Вот мой код для некоторого дополнительного контекста:
void Node::print() {
Node *temp = this; //points to the node that calls the print function
while (temp->next != NULL) {
cout << "Name: " << temp->name << "\tID: " << temp->ID << endl;
temp = temp->next; //makes temp->next point to the next node in the list.
}
//this line runs when temp->next == NULL
cout << "Name: " << temp->name << "\tID: " << temp->ID << endl;
}