title: C++ how to call a method defined in a class directly where only the reference to the class is returned by another function
body: <p>In my program, I have a grid class (e.g. <code>myGrid</code>) and I could obtain a reference to a cell (a class) by overloading the <code>operator()</code>. My problem is each time I call this <code>myGrid(x, y)</code> which returns a reference to a cell, I need to claim a cell reference. </p>
  
  <pre><code> cell&amp; myCell = myGrid(x,y);
   myCell.status = currentStatus; 
  </code></pre>
  
  <p>I got an error by doing this:</p>
  
  <pre><code>(myGrid(x,y)).status = currentStatus;
  </code></pre>
  
  <p>I need to use the function defined in cell very frequently. Thus, each time I need to claim a cell reference which makes my code look urgly. Is there any elegant way to solve the problem? Thanks very much. Cheers!</p>
  
  <p>Sorry. There is a typo. Let's assume status is a public varible in cell and assume currentStatus is a variable of the same type as status.</p>
  
  <p>Grid is a predefined class and I don't have the right to modify it. It returns a reference to cell.
  E.g. cell&amp; operator()(int x, int y)</p>
  
  <p>Sorry for the chaos. myGrid(x,y).status works. I made a mistake somewhere before. When I complied it, the error occurred in this line. Thanks very much!</p>