I think you misunderstood what I was trying to say. My question is how to write an accessor function for a private member variable array, not on how to call the accessor member function.
the problem is that i need all the elements from the array, This is basically what i have,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class myClass
{
public:
...
getMyArray();
private:
...
int myArray[10];
};
int main()
{
...
// I need to access all the elements of the array here
return 0;
}
If you need access to all of the elements at once then return a pointer from the function.
Return a constant* if you don't want the user to change the array values.
constint* getMyArray(){ return myArray; }
To return a single value stored in the array, pass an int argument and return an int result:
Using (e.g.) getElemCount(), getElem() still allows you to access all elems, but would allow you to check that accessing is only done with a valid index.