请帮助我,在双向链表中实现重载运算符++。我有A和B两个班。
class A {
private:
int h;
int a;
public:
A *next, *prev;
friend A operator ++(A &, int);
};
A operator ++(A &t, int) {
A temp = t;
temp.h++;
temp.a++;
return temp;
}
class B {
private:
A *head, *tail;
public:
void incValue();
};
void B::incValue() {
while(head != nullptr) {
head++;
head = head -> next;
}
}
执行方法后 incValue() head = NULL 我不明白为什么这不起作用。
PS此代码必须是eq。头++
head -> setH(head -> getH() + 1);
head -> setA(head -> getA() + 1);