对于我的编程类,我必须编写一个链表类。我们必须包括的功能之一是next()。该函数将返回列表中下一个元素的内存地址。返回一个类的指针
#include <iostream>
using namespace std;
class Set {
private:
int num;
Set *nextval;
bool empty;
public:
Set();
<some return type> next();
};
<some return type> Set::next() {
Set *current;
current = this;
return current->next;
}
int main() {
Set a, *b, *c;
for (int i=50;i>=0;i=i-2) a.insert(i); // I've ommited since it does not pertain to my question
// Test the next_element() iterator
b = a.next();
c = b->next();
cout << "Third element of b = " << c->value() << endl;
return 0;
}
正如你所看到的,我需要设置指针*b
和*c
到保存在列表中的下一个元素的内存地址。我的问题是我会使用什么样的返回类型?我试过把Set和Set *替换成编译器错误。任何帮助是极大的赞赏。