title: How to access private array in a class in c++
body: <pre><code>Struct S
  {int a,b,c};
  
  class A{
      S myArray[MAX]
      void fillArrayFromFile();
  };
  
  class B{
      void printStyle1();
      void printStyle2();
      void printSTyle3();
  };
  
  class C{
      void printStyle4();
      void printStyle5();
      void printSTyle6();
  };
  </code></pre>
  
  <p>So given that bit of pretend code ...</p>
  
  <p>I want classes B and C  to be able to read information from the array in class A without being able to change the data.</p>
  
  <p>Accessor functions would be exceedingly cumbersome since I would have to write a function for each different output format or else create a temporary struct to hold the data and pass it to the calling class so it can . This doesn't seem like the best solution.</p>
  
  <p>A friend function would give access to members of the class, but not the instance I need to get to (unless I'm misunderstanding friend functions ...)</p>
  
  <p>making the array public would allow classes other than the two I wish to have access to access/manipulate the data.</p>