Image

Messy thing...

This is a style thing only. I've got a class that stores some data in an array. Now, I have other classes that need read-only access to all of that data. Right now I'm just returning the array, which isn't what I want. Nor do I want to create a mountain of access methods. Is there some short way to return a copy of the array, thereby protecting the data in it?

The array is small, and the size is fixed, and I could copy easily in a loop, but I'm wondering if there's a better way to solve this. It seems like there should be; returning references to protected data seems like a bad idea to me.