Array within a Class
Arrays can be used as data members in a class. an Array can be a private or a public data member of the class. If an array is a private data member of the class, then only the member functions of the class can access it. Otherwise if an array is a public data member of the class, it can be accessed directly using objects of the class type. Consider the following class definition:
class myarray
{
int a[20];
public;
void getval(void);
void display(void);
};
Here, the arrray a is declared as a as a private member of the class myarray. It can be accessed only through the member functions of the class like any other private data member . The member function getval() reads the values of elements of the array a and the member function display() prints the values of elements of the array a. LEARN MORE>>
No comments:
Post a Comment