我正在处理链表,但无法修改 const 函数“void Print() const”中当前指针的值
在函数打印中,我想做“current=head”,然后像“current=current->link”一样递增,但不能这样做,bcz 表明
“错误 C3490:'current' 无法修改,因为它正在通过 const 对象 e:\Cpp\projects\data structure ass-1\data structure ass-1\source.cpp 83 1 Data Structure Ass-1 访问”
#include<iostream>
struct node
{
int data;
node *link;
};
class List
{
node *head,*current,*last;
public:
List();
// List(const List&);
// ~List();
void print() const;
};
using namespace std;
int main()
{
List List1;
}
void List::print() const
{
current=head; //here is my error
current=current->link;
}
List::List():current(head)
{
}