Static member modification in const member function in C++
I am working on linked-list but can't modifying the value of current
pointer in const function "void Print() const"
Here in print function i want to do "current= head" & then increment like
"current=current->link" but can't do so, bcz it is showing that
"error C3490: 'current' cannot be modified because it is being accessed
through a const object 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)
{
}
No comments:
Post a Comment