title: referencing objects in a global structure
body: <p>I have a simple matrix and vector class:</p>
  
  <pre><code>class Matrix
  {
  public:
      Matrix(unsigned nrows = 1, unsigned ncols = 1);
      virtual ~Matrix() {} 
  
      //operators
      virtual float&amp; operator() (unsigned row, unsigned col); 
      virtual float  operator() (unsigned row, unsigned col) const;
  
      ... other stuff ...
  
  protected:
      unsigned mRows;
      unsigned mCols;
      vector&lt;float&gt; MatrixData;
  };    
  
  // vector class and methods ( n x 1 matrix)
  class VectorM: public Matrix
  {
  public:
      VectorM(unsigned nRows = 1);
      virtual ~VectorM(){} // Destructor
  
      //operators
      float&amp; operator() (unsigned row); 
      float  operator() (unsigned row) const;
  };
  </code></pre>
  
  <p>I am running this code on an embedded system, so I want it to run as fast as possible. In the function that uses these objects, instead of making the objects local (and hence creating and destroying them every time the function runs), I want to put them into a global struct defined as</p>
  
  <pre><code>typedef struct {
      VectorM dQuat(4);
      VectorM aQuat(4);
      VectorM attErr(3);
      VectorM ex_hat(3); 
      VectorM ex_d(3);
      VectorM ez_d(3);
      VectorM v(3); 
      VectorM ey_p(3);
      VectorM ez_p(3);
  
      Matrix Rvb_hat(3,3);
      Matrix Rvb_d(3,3); 
      Matrix RZ(3,3);
      Matrix v_hat(3,3);
      Matrix Rp(3,3);
      Matrix I(3,3);
  
  }tRTT;
  </code></pre>
  
  <p>and instantiated and referenced by (I know the function isn't necessary, but I'm being consistent with existing code)</p>
  
  <pre><code>tRTT gRTT;
  tRTT *GetRTTPointer(void)
  {
      return(&amp;gRTT);
  }
  </code></pre>
  
  <p>The functions that use the struct are</p>
  
  <pre><code>void StepInnerLoop()
  {
      ... stuff ...
      float bodyError[3];
      tRTT *RTT = GetRTTPointer();
  
      // these appear to be fine
  RTT-&gt;dQuat(1) = desQuat[0]; RTT-&gt;aQuat(1) = attitudeQuat[0];
  RTT-&gt;dQuat(2) = desQuat[1]; RTT-&gt;aQuat(2) = attitudeQuat[1];
  RTT-&gt;dQuat(3) = desQuat[2]; RTT-&gt;aQuat(3) = attitudeQuat[2];
  RTT-&gt;dQuat(4) = desQuat[3]; RTT-&gt;aQuat(4) = attitudeQuat[3];
  
  ResolvedTiltTwist(RTT);
  
  bodyError[0] = RTT-&gt;attErr(1); // ERROR #1 HERE
  bodyError[1] = RTT-&gt;attErr(2);
  bodyError[2] = RTT-&gt;attErr(3);   
  
  ... other stuff ...
  }
  
  void ResolvedTiltTwist(tRTT *RTT)
  {
      float thetaTilt, thetaSign;
  
      Quat2DirectionCosine(RTT-&gt;Rvb_hat,RTT-&gt;aQuat); //ERROR #2 HERE
      RTT-&gt;ex_hat(1) = RTT-&gt;Rvb_hat(1,1); 
      RTT-&gt;ex_hat(2) = RTT-&gt;Rvb_hat(1,2); 
      RTT-&gt;ex_hat(3) = RTT-&gt;Rvb_hat(1,3); 
  
      ...stuff...
  }
  
  void Quat2DirectionCosine(Matrix&amp; dc, const VectorM&amp; e)
  {
     ... stuff ...
  }
  </code></pre>
  
  <p>I get two errors - error #1 is No suitable conversion function from "VectorM" to "float" exists and error #2 is a pointer to a bound function may only be used to call the function.</p>
  
  <p>If all the objects are declared in the StepInnerLoop or ResolvedTiltTwist functions, then all is well. Any thoughts?</p>
  
  <p>Thanks in advance.</p>