i need to overload a constructor to specify dimensions in a 2-d array and check to see if its within the bounds of 10x10. and i keep getting errors on my attempt. for clarity ill just include the whole class.
Code:
class matrix
{
private:
int lim1,lim2;
int mtx[lim1][lim2];
public:
matrix(): lim1(10),lim2(10)
{ }
matrix(int x,int y): lim1(x),lim2(y) //RESTRICT defined as 10
{
if(x < RESTRICT-1 || y < RESTRICT-1)
{
lim1 = x;
lim2 = y;
}
else
cout << "Error: specified array too large." << endl;
}
void putel(int index1,int index2,int value)
{
if(index1 <= RESTRICT-1 && index2 <= RESTRICT-1)
mtx[index1][index2] = value;
else
cout << "Error: exceeded limits of array" << endl;
}
int getel(int index1,int index2)
{
if(index1 <= RESTRICT-1 && index2 <= RESTRICT-1)
{
int tmp = mtx[index1][index2];
return tmp;
}
else
cout << "Error: exceeded limits of array" << endl;
}
};
//errors
ch7_ex10.cpp:11: error: invalid use of member `matrix::lim1'
ch7_ex10.cpp:11: error: invalid use of member `matrix::lim2'
ch7_ex10.cpp: In member function `void matrix::putel(int, int, int)':
ch7_ex10.cpp:29: error: `mtx' undeclared (first use this function)
ch7_ex10.cpp:29: error: (Each undeclared identifier is reported only once for
each function it appears in.)
cant figure out why it says invalid use of member...help much appreciated. thanks in advance