リンクリストに取り組んでいますが、const 関数 "void Print() const" の現在のポインターの値を変更できません
関数 Print で、「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)
{
}