Good day to all the good!
Here's a seemingly error in this code, all right. I don't understand why there is an error. Tell me, please!
Code:
class A
{
private:
int mas100[100]; //error: 'int A::mas100 [100]' is private
public:
int& operator[](int n)
{
//if(n < 0 || n >= 100) exit(-1);
try
{
if(n < 0 || n >= 100)
{
throw "Error!!!!"; //створити символьний рядок
}
}
catch(char *str)//сюди передасться рядок
{
printf(str);
}
return mas100[n];
}
};
Code:
A a1;
for(int i=0; i<100; i++)
{
a1.mas100[i]=i; //error: within this context
}
for(int j = 0; j < 100; j++)
{
int temp = a1[j]; // використовуємо функцію праворуч від знака =
}
||=== Build: Debug in Mistructur1 (compiler: GNU GCC Compiler) ===|
D:\Classes\Mistructur1\Mistructur1.cpp||In function 'int main()':|
D:\Classes\Mistructur1\Mistructur1.cpp|81|error: 'int A::mas100 [100]' is private|
D:\Classes\Mistructur1\Mistructur1.cpp|122|error: within this context|
D:\Classes\Mistructur1\Mistructur1.cpp|126|warning : unused variable 'temp' [-Wunused-variable]|
||=== Build failed: 2 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|