declaration of 2d array in the class and its latter usage

I am trying to have a declaration of 2d array in private part of my class and then latter on, the functions of this class will use and modify the values in the array, but I am getting an error which says “I-value specified const object”. What is wrong with this code and how can I fix it?

Here is a simple code demonstrating my problem

in someClass.h________________

class someClass
{
public:
    //Some code here

private:

    char grid[20][20];

    //Some code here

}

in someClass.cpp______________

lets say one of the functions is trying to reassign the value of item in position (0,0) like so.

grid[0][0]='*';

This gives me an error saying, expression must be modifiable lvalue.


Source: c++

Leave a Reply