hi can anybody please expalin me that can i access the array(arr) which is declared as a private member of the class(array) by using public function (display). The code is given here...
#include<iostream.h>
const int size= 8;
class array
{
int arr[size];
int i;
public:
array();
void display(int arr[size]);
};
array::array()
{
i=0;
arr[0]=21;
arr[1]=55;
arr[2]=16;
arr[3]=11;
arr[4]=51;
arr[5]=67;
arr[6]=5;
arr[7]=8;
}
//traversal of an array
void array::display(int arr[size])
{
for(i=0;i<size;i++)
cout<<arr[i]<<"\t";
cout<<endl;
}
int main()
{
array ob1;
ob1.display(arr[8]);
return 0;
}
when i try to compile the code it gives the following error:
test.cpp:42: error: arr was not declared in this scope
please help!
thanks in advance