Accessing a 2D array between two friend classes
<p>My question is how to access and modify a 2D array defined in one class that is friends with another class. Below are some details on my question:</p>

<p>In <code>class A</code> I declare and allocate the appropriate space for my 2D array (pointer-to-pointer) u. </p>

<pre><code>Class A
{
   public:
   friend class B;
   long double **u; 
   int fun;
   void make(); 
};
void A::make()
{
  long double **u = new long double *[nx];
  for (int i=0;i&lt;nx;i++)
  u[i] = new long double [ny];
  int fun = 9;
}
</code></pre>

<p><code>Class A</code> is friends with <code>Class B</code>; I need to use the array I declared in <code>Class A</code> in a function defined in <code>class B</code>. Below is my Class B:</p>

<pre><code>class B
{
   public:
   void get(A*);
};

void B::get(A *pt)
{
   using namespace std;
   cout &lt;&lt; pt-&gt;fun;
   cout &lt;&lt; pt-&gt;u[0][0];
}
</code></pre>

<p>I get a Bus error on my second cout <code>pt-&gt;u[0][0]</code>. Is there a simple way to use this setup I have to access my u[][] array? I think that I get the error because the pointer points to the 1st entry of my array, thus my whole 2D array is saved in memory as a single row (thinking aloud here). I'm a Fortran guy so this stuff is a little new to me.</p>

<p>Any help or "pointers" to other helpful threads would be appreciated.</p>

<p>Thank you !</p>

<p>Alberto</p>
