Array within a Class

The array can be used as member variables in a class. The following class definition is valid.

const int size=10;

class array
int a[size];
void setval(void);
void display(void);

The array variable a[] declared as private member of the class array can be used in the member function, like any other array variable. We can perform any operations on it. For instance, in the above class definition, the member function setval() sets the value of element of the array a[], and display() function displays the values. Similarly, we may use other member functions to perform any other operation on the array values.

No comments:

Post a Comment